Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid pusgbutton event

Status
Not open for further replies.

Caradog

Programmer
Jun 28, 2000
73
GB
Guys, I got a datagrid...

DataGrid1.BorderWidth = Unit.Pixel(2)
DataGrid1.CellPadding = 6
DataGrid1.GridLines = GridLines.Both
DataGrid1.BorderColor = Color.Black
DataGrid1.ShowHeader = True
DataGrid1.AutoGenerateColumns = False
DataGrid1.SelectedItemStyle.BackColor = Color.Beige

'add bound columns to the datagrid
Dim datagridcol As New BoundColumn
datagridcol.HeaderText = "Brand Name"
datagridcol.DataField = "strName"
DataGrid1.Columns.Add(datagridcol)

...and I've added a command...

Dim selectcol1 As New ButtonColumn
selectcol1.ButtonType = ButtonColumnType.PushButton
selectcol1.HeaderText = ""
selectcol1.Text = "Edit"
selectcol1.CommandName = "Edit Brand"
DataGrid1.Columns.Add(selectcol1)

...then I got an event handler to catch the "EditBrand" command which works as so...

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
Select Case e.CommandName
Case "Edit Brand"
Response.Write("EDIT PRESSED")
End Select
End Sub

...how the hell do I now get the name, id, whatever of the row I just clicked on?

- Jay
code@jay-hayman.co.uk
 
Jay --

Try using a variation of:

Dim strLastName As String
Dim strFirstName As String
Dim strTitle As String
strLastName = E.Item.Cells(0).Text
strFirstName = E.Item.Cells(1).Text
strTitle = E.Item.Cells(2).Text

...running short of time so can't test, these variables can be obtained from the EventArgs E...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top