Currently, I have a static datagrid on a webapplication. I was doing some research and it seems there are no pointers on this datagrid .I have multiple records been shown in the grid from a SQL query from time to time instead of a single record. And when either result occurs in the grid, I want to go the next page when I press a button.
I want my information from the grid to show up in textboxes on the next page when I do a Server.transfer(""). However, I want the grid to be selectable so that whatever row is selected that the items in the grid row selected appear in the next page's textboxes. The best I have found is to play with the grid color to highlight in yellow during onclick which looks like this:
Code:Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound If (e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer) And _ (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then e.Item.Attributes.Add("onClick", "this.style.backgroundColor='Yellow'; this.style.color='Black'") If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='Gainsboro'; this.style.color='Black'") End If If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer And e.Item.ItemType = ListItemType.Item Then e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='White'; this.style.color='Black'") If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='Whitesmoke'; this.style.color='Black'") End If
Then I would store the values here:
and then by the next page verify.aspx do the following:Code:Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles btnOpen.Click context.Items("Storage1") = DataGrid1.Items(0).Cells(0).Text context.Items("Storage2") = DataGrid1.Items(0).Cells(1).Text context.Items("Storage3") = DataGrid1.Items(0).Cells(2).Text context.Items("Storage4") = DataGrid1.Items(0).Cells(3).Text context.Items("Storage5") = DataGrid1.Items(0).Cells(4).Text Context.Items("Storage6") = DataGrid1.Items(0).Cells(5).Text Server.Transfer("Verify_Iss.aspx")
Right now it just takes the first row from the grid and that 's it on how it is written currently.Code:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not IsPostBack Then TextBox1.Text = Context.Items("Storage1") TextBox2.Text = Context.Items("Storage2") TextBox3.Text = Context.Items("Storage3") end if




Reply With Quote