I have a Master page and a content page. The content page contains a gridview that is databound from a Dictionary<key, myObject> collection. The 2nd column in the GridView control is an <asp:CheckBox ..> control. I select a few of the CheckBoxes and
click on a menu item to post, however every checkbox is returning false.
Here is the code that I use to iterate through the grid: Any suggestions are appreciated. Thanks.
Is the checkbox bound to data somewhere? I haven't tried to use an unbound checkbox as a selector. Its possible that the order of events in ASP might be messing you up. But I think you may want to try creating an array to store your checkbox values and
update it on the checkbox's CheckChanged event. That way you take the order of event execution out of the equation.
I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
DeskingFan
Member
4 Points
48 Posts
Gridview CheckBox with Master Page
Oct 01, 2007 03:49 PM|LINK
Hello All,
I have a Master page and a content page. The content page contains a gridview that is databound from a Dictionary<key, myObject> collection. The 2nd column in the GridView control is an <asp:CheckBox ..> control. I select a few of the CheckBoxes and click on a menu item to post, however every checkbox is returning false.
Here is the code that I use to iterate through the grid: Any suggestions are appreciated. Thanks.
myGridView = (GridView) ContentPlaceHolderPaymentViews.FindControl("gvwDeals");if (myGridView != null){
// Select the checkboxes from the GridView controlfor (int i = 0; i < myGridView.Rows.Count; i++){
GridViewRow row = myGridView.Rows[i]; bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked; if (isChecked){
//do something here
}
}
}
triggered
Contributor
3356 Points
909 Posts
Re: Gridview CheckBox with Master Page
Oct 01, 2007 04:25 PM|LINK
Did you enable view state with enableViewState = true;
if you do...
Also, are you binding your data on every page load? This will re-populate your grid. You should only populate it on first page load
if(!Page.IsPostback) { // Bind data to grid }Charles Asbo...
Contributor
5512 Points
1186 Posts
Re: Gridview CheckBox with Master Page
Oct 01, 2007 04:27 PM|LINK
Is the checkbox bound to data somewhere? I haven't tried to use an unbound checkbox as a selector. Its possible that the order of events in ASP might be messing you up. But I think you may want to try creating an array to store your checkbox values and update it on the checkbox's CheckChanged event. That way you take the order of event execution out of the equation.
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
DeskingFan
Member
4 Points
48 Posts
Re: Gridview CheckBox with Master Page
Oct 01, 2007 06:13 PM|LINK
Thanks, I forgot to put the "if (!Page.IsPostback)" before before binding the GridView.
oops.