Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event

Last post 07-11-2008 2:54 AM by Samu Zhang - MSFT. 5 replies.

Sort Posts:

  • Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event

    07-10-2008, 5:35 AM

    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.

  • Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event

    07-10-2008, 7:46 AM

    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.
  • Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event

    07-10-2008, 7:56 AM

    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....

  • Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event

    07-10-2008, 8:09 AM
    • Contributor
      5,709 point Contributor
    • Pushkar
    • Member since 02-17-2006, 7:27 AM
    • Vibrant Gujarat
    • Posts 1,085

     MyCheckBox = (CheckBox)DataGrid1.Items(0).FindControl("CheckBox1");

    For further detail.

     http://66.129.67.4/p/1230647/2229994.aspx#2229994
     

    “ There is no great genius without some touch of madness. ”


    Remember to click “Mark as Answer” on the post If you get answer from my post(s) !

    Thanks Guys
    ------------
    Pushkar M Rathod
  • Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event

    07-10-2008, 8:20 AM

    DataGrid1.Items(0) will return the first item row and will not return the header row.

  • Re: Accessing CheckBox in headertemplate of datagrid in datagrid's pageindexchanged event

    07-11-2008, 2:54 AM
    Answer

    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.
Page 1 of 1 (6 items)