|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GridView current row??I've got a Grid with 5 fields, 2 are templatefields that contain checkbox
controls. When I check on a checkbox in my GridView the _CheckedChanged event is fire -- all good so far... Now how do I determine which row & checkbox was triggered the event in the GridView (where my checkbox was checked)? the sender object does not provide any info, nor the e EventArgs. my GridView has a selectedIndex but that is always -1. Keep in mind the grid is NOT in edit mode (templateFields). Basically I just want to know which checkbox in my GridView triggered the CheckedChanged event so I can then get the row and update other fields within that row. Any suggestions? Rob,
If you are handling the CheckedChanged event of the checkbox then the sender is the checkbox and the NamingContainer would be the GridViewRow, e.g. CheckBox chk= (CheckBox)sender ; GridViewRow gvr= (GridViewRow)chk.NamingContainer ; Int32 rowIndex = gvr.RowIndex; string strPrimaryKey = GridView1.DataKeys[rowIndex]].Value.ToString(); //you can use the strPrimaryKey to identify the record that you need to process Show quoteHide quote "Rob R. Ainscough" wrote: > I've got a Grid with 5 fields, 2 are templatefields that contain checkbox > controls. When I check on a checkbox in my GridView the _CheckedChanged > event is fire -- all good so far... Now how do I determine which row & > checkbox was triggered the event in the GridView (where my checkbox was > checked)? > > the sender object does not provide any info, nor the e EventArgs. my > GridView has a selectedIndex but that is always -1. > > Keep in mind the grid is NOT in edit mode (templateFields). > > Basically I just want to know which checkbox in my GridView triggered the > CheckedChanged event so I can then get the row and update other fields > within that row. > > Any suggestions? > > > Thank you, perfect.
Show quoteHide quote "Phillip Williams" <WEBSWAPP@newsgroups.nospam> wrote in message news:657F1308-3D5E-4DF0-843F-F000E0BAD15E@microsoft.com... > Rob, > > If you are handling the CheckedChanged event of the checkbox then the > sender > is the checkbox and the NamingContainer would be the GridViewRow, e.g. > > CheckBox chk= (CheckBox)sender ; > GridViewRow gvr= (GridViewRow)chk.NamingContainer ; > Int32 rowIndex = gvr.RowIndex; > string strPrimaryKey = GridView1.DataKeys[rowIndex]].Value.ToString(); > //you can use the strPrimaryKey to identify the record that you need to > process > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Rob R. Ainscough" wrote: > >> I've got a Grid with 5 fields, 2 are templatefields that contain checkbox >> controls. When I check on a checkbox in my GridView the _CheckedChanged >> event is fire -- all good so far... Now how do I determine which row & >> checkbox was triggered the event in the GridView (where my checkbox was >> checked)? >> >> the sender object does not provide any info, nor the e EventArgs. my >> GridView has a selectedIndex but that is always -1. >> >> Keep in mind the grid is NOT in edit mode (templateFields). >> >> Basically I just want to know which checkbox in my GridView triggered the >> CheckedChanged event so I can then get the row and update other fields >> within that row. >> >> Any suggestions? >> >> >> |
|||||||||||||||||||||||