gridview selected index returns -1 out of range exception
-
hi all I am trying to write a code wherein when user click on the row the particular checkbox will be checked/unchecked. My code for this is CheckBox cb = (CheckBox)GridView1.Rows[selectedindex].FindControl("checked"); which returns -1; Please suggest soln to it. Tejesh
-
hi all I am trying to write a code wherein when user click on the row the particular checkbox will be checked/unchecked. My code for this is CheckBox cb = (CheckBox)GridView1.Rows[selectedindex].FindControl("checked"); which returns -1; Please suggest soln to it. Tejesh
it should be help u or u pass incorrect control name chkSelect # foreach (GridViewRow row in uxgridAllActivities.Rows) { # //' Access the CheckBox # CheckBox cb = (CheckBox)row.FindControl("chkSelect");
Piyush Vardhan Singh p_vardhan14@rediffmail.com http://holyschoolofvaranasi.blogspot.com http://holytravelsofvaranasi.blogspot.com
-
hi all I am trying to write a code wherein when user click on the row the particular checkbox will be checked/unchecked. My code for this is CheckBox cb = (CheckBox)GridView1.Rows[selectedindex].FindControl("checked"); which returns -1; Please suggest soln to it. Tejesh
First of all what type of control is causing the postback? I'm going to assume it is a button. Button ButtonClicked = (Button)sender; GridViewRow gvr = (GridviewRow)ButtonClicked.namingContainer; CheckBox cb = (CheckBox) gvr.findcontrol("cbId"); cb.checked = true;
I didn't get any requirements for the signature
-
it should be help u or u pass incorrect control name chkSelect # foreach (GridViewRow row in uxgridAllActivities.Rows) { # //' Access the CheckBox # CheckBox cb = (CheckBox)row.FindControl("chkSelect");
Piyush Vardhan Singh p_vardhan14@rediffmail.com http://holyschoolofvaranasi.blogspot.com http://holytravelsofvaranasi.blogspot.com
Hi Thx for the Reply protected void grid_row_command(object sender, GridViewCommandEventArgs e) { GridView g = (GridView)sender; int selectedindex = g.SelectedIndex; string commandname = e.CommandName; switch (commandname) { case ("singleclick"): // Response.Write("Single Click"); CheckBox cb = (CheckBox)g.Rows[selectedindex].FindControl("checked"); if (cb.Checked) cb.Checked = false; else cb.Checked = true; break; case ("doubleclick") : Response.Write("DoubleClcik"); break; } } i am trying to write the set the selected index on OnRowCommand="grid_row_command" for my gridview I dont know where i am going wrong.. Waiting for reply
modified on Friday, January 9, 2009 12:10 AM