Results 1 to 3 of 3

Thread: Checkbox in Gridview Header

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    105

    Checkbox in Gridview Header

    I wnat to have checkbox in Gridview Header. On the checkbox changed I wnat to check and uncheck all the checkboxes of the Gridview Rows. Currently I am doing it on the button click. But I want to have checkbox in Gridview header, How to have checkbox in Gridview Header,can somebody tell me??
    Code:
    protected void btnCheckAll_Click(object sender, EventArgs e)
        {
            Check_Uncheck_Checkboxes(true);
        }
        protected void btnunCheckAll_Click(object sender, EventArgs e)
        {
            Check_Uncheck_Checkboxes(false);
        }
    
        private void Check_Uncheck_Checkboxes(bool bState)
        {
            CheckBox chk;
            foreach (GridViewRow rowItem in GrdCompanies.Rows)
            {
                chk = (CheckBox)(rowItem.Cells[1].FindControl("chkSelect"));
                chk.Checked = bState;
               
            }
        }

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Checkbox in Gridview Header

    Hey,

    You could do this work in the RowCreated event of the GridView.

    http://msdn.microsoft.com/en-us/libr...owcreated.aspx

    Check to see if the RowType is the Header, and if it is, add the necessary controls, and hook up the event handles.

    Either that, or edit the HeaderTemplate for the column that you are interested in.

    Gary

  3. #3
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Checkbox in Gridview Header

    hay,
    you can use the HeaderTemplate

    Code:
    <asp:GridView ID="GridView2" runat="server">
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" Text="Header " />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width