i am trying to access CheckBox in headertemplate of datagrid, soon after binding data to the grid in the pageindexchanged event.
i get a NullReferenceException when i do that. Could not find the reason. i have already done this accessing of header control elsewhere in my application, but have not had any problem before. Is it any thing to do with the pageindexchanged event.
CheckBox chkSelect = (CheckBox)GridView1.HeaderRow.FindControl("chkSelect"); // here in paranthesis of findcontrol() method, give the id of checkox in headertemplate.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
it is not a grid view, it is a datagrid. Datagrid does not have a property called HeaderRow. I sorted out the issue by fetching the header control using Datagrid.Controls[0].Controls[1].
What i am not able to understand is, in CheckedChange event of control in itemtemplate of the datagrid i fetched using Datagrid.Controls[0].Controls[0], whereas in pageIndexChanged event i fetched it as Datagrid.Controls[0].Controls[1]. what is the difference.
how does grid structure differ in the above two cases. wierd....
chk = childtable.Rows[0].FindControl("idhere")
as CheckBox;
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
anupreethi20...
Member
4 Points
22 Posts
Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event
Jul 10, 2008 09:35 AM|LINK
i am trying to access CheckBox in headertemplate of datagrid, soon after binding data to the grid in the pageindexchanged event.
i get a NullReferenceException when i do that. Could not find the reason. i have already done this accessing of header control elsewhere in my application, but have not had any problem before. Is it any thing to do with the pageindexchanged event.
i access the header control using
System.Web.UI.Control header = _kdmGeneratorGrid.Controls[0].Controls[0];((
CheckBox)header.FindControl("_selectAllChkBx")).Checked = Convert.ToBoolean(_isAllSelected.Value);i have done the same in the _selectAllChkBx onCheckedChange Event.
Please help.
ramireddyind...
All-Star
31358 Points
4579 Posts
Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event
Jul 10, 2008 11:46 AM|LINK
CheckBox chkSelect = (CheckBox)GridView1.HeaderRow.FindControl("chkSelect"); // here in paranthesis of findcontrol() method, give the id of checkox in headertemplate.
anupreethi20...
Member
4 Points
22 Posts
Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event
Jul 10, 2008 11:56 AM|LINK
it is not a grid view, it is a datagrid. Datagrid does not have a property called HeaderRow. I sorted out the issue by fetching the header control using Datagrid.Controls[0].Controls[1].
What i am not able to understand is, in CheckedChange event of control in itemtemplate of the datagrid i fetched using Datagrid.Controls[0].Controls[0], whereas in pageIndexChanged event i fetched it as Datagrid.Controls[0].Controls[1]. what is the difference. how does grid structure differ in the above two cases. wierd....
Pushkar
Contributor
5747 Points
1111 Posts
Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event
Jul 10, 2008 12:09 PM|LINK
MyCheckBox = (CheckBox)DataGrid1.Items(0).FindControl("CheckBox1");
For further detail.
http://66.129.67.4/p/1230647/2229994.aspx#2229994
====================================
Pushkar
anupreethi20...
Member
4 Points
22 Posts
Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event
Jul 10, 2008 12:20 PM|LINK
DataGrid1.Items(0) will return the first item row and will not return the header row.
Samu Zhang -...
All-Star
62163 Points
6101 Posts
Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event
Jul 11, 2008 06:54 AM|LINK
Hi anupreethi2001 ,
Try this way:
Table
childtable = dg.Controls[0] as Table;CheckBox
chk = childtable.Rows[0].FindControl("idhere") as CheckBox;Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
praveen.sing...
Member
180 Points
41 Posts
Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event
Nov 06, 2012 05:12 AM|LINK
Thanks Dear Its solv my problem
Praveen Singh
Software Engineer
http://praveensinghbisen.blogspot.com/