|
|
 |
| ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

August 12th, 2009, 11:41 AM
|
|
Authorized User
|
|
Join Date: Apr 2006
Location: london, , United Kingdom.
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
can't get checkbox value from Gridview
Hi All
I am populating a grid at runtime/on-the-fly which is fine.
But when I want to get a value of a check-box in the grid I am getting error.
I can't use the findcontrol as it doesn't exist for any of the controls.
Please help me.
CodeBehind:-
Code:
protectedvoid GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
bool att = false;
GridViewRow gvrow = GridView1.Rows[e.RowIndex];
CheckBox chk_SelectCheckbox = (CheckBox)gvrow.Cells[4].Controls[1]; //checkbox to capture chkbox selection
}
Error screenshot
Server Error in '/Event' Application.
Specified argument was out of the range of valid values.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
Source Error:
Line 135: bool att = false;Line 136: GridViewRow gvrow = GridView1.Rows[e.RowIndex];Line 137: CheckBox chk_SelectCheckbox = (CheckBox)gvrow.Cells[4].Controls[1]; //checkbox to capture chkbox selectionLine 138: Line 139:
Source File: c:\Documents\Visual Studio 2008\Event\UpdateAttendance.aspx.cs Line: 137
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.Parameter name: index] System.Web.UI.ControlCollection.get_Item(Int32 index) +8668910 UpdateAttendance.GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e) in c:\Users\Mayur\Desktop\Data\urvashi\Documents\Visu al Studio 2008\IndianSpeedDating\UpdateAttendance.aspx.cs:13 7 System.Web.UI.WebControls.GridView.OnRowUpdating(G ridViewUpdateEventArgs e) +133 System.Web.UI.WebControls.GridView.HandleUpdate(Gr idViewRow row, Int32 rowIndex, Boolean causesValidation) +720 System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean causesValidation, String validationGroup) +704 System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source, EventArgs e) +95 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source, EventArgs e) +123 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +118 System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String eventArgument) +135 System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074
|

August 12th, 2009, 12:38 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 807
Thanks: 12
Thanked 140 Times in 140 Posts
|
|
Don't forget these indexes are zero-based.
If you want to target the 4th cell in the row, you'd use Cells[3].
If the checkbox is the only control in that cell, you'd use Controls[0].
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|

August 21st, 2009, 01:45 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Location: singapore, singapore, Singapore.
Posts: 49
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
i would i advise you to use findControl of the respective row. This way even if you add some more controls in the future it wont break at runtime
gvrow.Cells[4].FindControl()
|
|
The Following User Says Thank You to pons_saravanan For This Useful Post:
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |