mitharatowen
06-28-2006, 07:52 PM
hello everyone, my code is long and complex (probably unnessiarily so as I am new and dont know all the coding protocol and shortcuts) but here's a snippet of the part I am having trouble with.
Public Sub SetGridProperties(theGrid, num)
'declare a new datagrid and set properties
theGrid.Width = Unit.Pixel(700)
theGrid.BorderWidth = Unit.Pixel(2)
theGrid.CellPadding = 10
theGrid.GridLines = GridLines.Both
theGrid.BorderColor = Color.Blue
theGrid.ShowHeader = True
theGrid.AutoGenerateColumns = False
theGrid.SelectedItemStyle.BackColor = Color.Yellow
'add bound columns to the datagrid
Dim datagridcol As New BoundColumn()
datagridcol.HeaderText = "Option Number"
datagridcol.DataField = "OptionNumber"
theGrid.Columns.Add(datagridcol)
datagridcol = New BoundColumn()
datagridcol.HeaderText = "Manufacturing Part Number"
datagridcol.DataField = "ManfPartNumber"
theGrid.Columns.Add(datagridcol)
datagridcol = New BoundColumn()
datagridcol.HeaderText = "Description"
datagridcol.DataField = "Description"
theGrid.Columns.Add(datagridcol)
datagridcol = New BoundColumn()
datagridcol.HeaderText = "List Price"
datagridcol.DataField = "ListPrice"
theGrid.Columns.Add(datagridcol)
Dim selectcol As New ButtonColumn()
selectcol.ButtonType = ButtonColumnType.LinkButton
selectcol.Text = "Select"
selectcol.CommandName = "Select"
theGrid.Columns.Add(selectcol)
'add event handlers
AddHandler CType(thegrid, DataGrid).SelectedIndexChanged, AddressOf DataGrid_SelectedIndexChanged
'bind datagrid
theGrid.DataSource = GetDataSet(num)
theGrid.DataBind()
end sub
Public Sub DataGrid_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
response.redirect("http://www.msn.com")
End Sub
Basically here I have created a dynamic datagrid in a placeholder, in the code above i am setting its properties and populating it from a database (set by the GetDataSet(num) function which is not shown). everything works as expected, the only problem I am having is that when you click on a "Select" button in a row in the grid, the DataGrid_SelectedIndexChanged sub doesnt seem to fire. I am not redirected to msn.com (just a test i put in there to see if the event fires, obviously not the final result) instead the page just does a post back and the datagrid disapears, which is due to it being dynamic it doesnt stick around, thats ok i just basically want to redirect to a new page with a querysting tacked on depending on which element was clicked. Now as i mentioned, im new so im probably doing something wrong here. could anyone please help me out? I need to redirect to a different page and i also need to pull out some of the data in the row that was clicked to put into the query string such as the contents of the Manufacturing Part Number column.
Thanks a bunch in advance! :thumbsup:
Public Sub SetGridProperties(theGrid, num)
'declare a new datagrid and set properties
theGrid.Width = Unit.Pixel(700)
theGrid.BorderWidth = Unit.Pixel(2)
theGrid.CellPadding = 10
theGrid.GridLines = GridLines.Both
theGrid.BorderColor = Color.Blue
theGrid.ShowHeader = True
theGrid.AutoGenerateColumns = False
theGrid.SelectedItemStyle.BackColor = Color.Yellow
'add bound columns to the datagrid
Dim datagridcol As New BoundColumn()
datagridcol.HeaderText = "Option Number"
datagridcol.DataField = "OptionNumber"
theGrid.Columns.Add(datagridcol)
datagridcol = New BoundColumn()
datagridcol.HeaderText = "Manufacturing Part Number"
datagridcol.DataField = "ManfPartNumber"
theGrid.Columns.Add(datagridcol)
datagridcol = New BoundColumn()
datagridcol.HeaderText = "Description"
datagridcol.DataField = "Description"
theGrid.Columns.Add(datagridcol)
datagridcol = New BoundColumn()
datagridcol.HeaderText = "List Price"
datagridcol.DataField = "ListPrice"
theGrid.Columns.Add(datagridcol)
Dim selectcol As New ButtonColumn()
selectcol.ButtonType = ButtonColumnType.LinkButton
selectcol.Text = "Select"
selectcol.CommandName = "Select"
theGrid.Columns.Add(selectcol)
'add event handlers
AddHandler CType(thegrid, DataGrid).SelectedIndexChanged, AddressOf DataGrid_SelectedIndexChanged
'bind datagrid
theGrid.DataSource = GetDataSet(num)
theGrid.DataBind()
end sub
Public Sub DataGrid_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
response.redirect("http://www.msn.com")
End Sub
Basically here I have created a dynamic datagrid in a placeholder, in the code above i am setting its properties and populating it from a database (set by the GetDataSet(num) function which is not shown). everything works as expected, the only problem I am having is that when you click on a "Select" button in a row in the grid, the DataGrid_SelectedIndexChanged sub doesnt seem to fire. I am not redirected to msn.com (just a test i put in there to see if the event fires, obviously not the final result) instead the page just does a post back and the datagrid disapears, which is due to it being dynamic it doesnt stick around, thats ok i just basically want to redirect to a new page with a querysting tacked on depending on which element was clicked. Now as i mentioned, im new so im probably doing something wrong here. could anyone please help me out? I need to redirect to a different page and i also need to pull out some of the data in the row that was clicked to put into the query string such as the contents of the Manufacturing Part Number column.
Thanks a bunch in advance! :thumbsup: