GridView Template Control [modified]
-
Hi all, I have a gridview with a list of names. My code allows me to select and highlight all names and save to database. However I want to be able to de-select a particular row; say I select all 100 Records but I later decide I don't want to select/save a particular record and I want to select only 99 Records. For this I've added a LinkButton Control into a Template Field of the Gridview. I want when this button is clicked to change the color (de-select) this particular row. However I am not able to get a reference to the row which I want to cancel. I know if I let the user click the autogenerated select button I can get a reference to it using (grdView.SelectedIndex) but I don't want to do this. I want to be able to click the 'cancel' button, get a reference to the corresponding row and change its background color. Anyway to do this? Thanks protected void grdViewCancelButton_Click(object sender, EventArgs e) { // Get Row you want to de-select //int SelectedIndex = ? // Change Row Background //grdView.Rows[SelectedIndex].BackColor = System.Drawing.Color.Whatever; }
modified on Tuesday, May 12, 2009 11:32 AM
-
Hi all, I have a gridview with a list of names. My code allows me to select and highlight all names and save to database. However I want to be able to de-select a particular row; say I select all 100 Records but I later decide I don't want to select/save a particular record and I want to select only 99 Records. For this I've added a LinkButton Control into a Template Field of the Gridview. I want when this button is clicked to change the color (de-select) this particular row. However I am not able to get a reference to the row which I want to cancel. I know if I let the user click the autogenerated select button I can get a reference to it using (grdView.SelectedIndex) but I don't want to do this. I want to be able to click the 'cancel' button, get a reference to the corresponding row and change its background color. Anyway to do this? Thanks protected void grdViewCancelButton_Click(object sender, EventArgs e) { // Get Row you want to de-select //int SelectedIndex = ? // Change Row Background //grdView.Rows[SelectedIndex].BackColor = System.Drawing.Color.Whatever; }
modified on Tuesday, May 12, 2009 11:32 AM
What if you set the CommandName of your linkbutton to Select or Cancel?? Also, you can set the CommandArgument of the linkbutton to the index of the corresponding row (from code in the rowdatabound event), and on postbacks you can access this property from code to know the index of the row clicked
Alexei Rodriguez
-
What if you set the CommandName of your linkbutton to Select or Cancel?? Also, you can set the CommandArgument of the linkbutton to the index of the corresponding row (from code in the rowdatabound event), and on postbacks you can access this property from code to know the index of the row clicked
Alexei Rodriguez
Thanks, This works :)
-
Thanks, This works :)
-
I'm actually using the select button for the meantime. If I will use the template linkbutton, I will go with the 2nd approach. On RowDataBound I will hook the linkbutton's CommandArgument to the Row Index and access this on the linkbutton's eventhandler. Thanks for the lead!