开发者

Selecting Multiple Check Boxes Inside a Grid View Control by clicking the Column Label Header

I have a grid view control with Template Field containing Item Template as Checkbox control and the Header Template is containing the label with column header name.

I want to click the coulmn header label and all the check boxes must be checked once.

Please provide me some examples or ideas how i can achieve this

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4"
        ForeColor="#333333" GridLines="None" >
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:TemplateField HeaderText="" >
            <ItemTemplate>
            <asp:CheckBox ID="val_id" runat="server" />
            开发者_Python百科</ItemTemplate>
            <HeaderTemplate>
            <label>
            Rise Needed
            </label>
            </HeaderTemplate>
            </asp:TemplateField>
        <Columns>


Change your HeaderTemplate label to be a LinkButton and assign the Click event.

        <HeaderTemplate>       
        <asp:LinkButton ID="btnRiseNeeded" runat="server" Text="Rise Needed" OnClick="btnRiseNeeded_Click" />       
        </HeaderTemplate>  

Then when the button is clicked loop through you GridView rows and check the box.

foreach(var row in GridView2.Rows)
{
   var cbx = (CheckBox)row.FindControl("val_id");
   cbx.Checked = true;
}

This code is off the top of my head so might need some modifying. Also, I'm not sure if the checkboxes will stay checked on PostBack. Give it a try.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜