Thursday, 19 January 2012

Selection With CheckBoxes In GridView

CheckBoxes Wise Selection In GridView

When You Require To do selectio of your data using checkboxes




Add This To HTML
<script language="javascript" type="text/javascript">

    function SelectAll(Id) {

        var myform = document.forms[0];

        var len = myform.elements.length;


        document.getElementById(Id).checked == true ? document.getElementById(Id).checked = false : document.getElementById(Id).checked = true;


        for (var i = 0; i < len; i++) {

            if (myform.elements[i].type == 'checkbox') {

                if (myform.elements[i].checked) {

                    myform.elements[i].checked = false;

                }

                else {

                    myform.elements[i].checked = true;

                 }

            }

        }

    }

</script>


And This To Your Server Side

  <asp:GridView runat="server" ID="GridView1" DataKeyNames="pck_id"
                             BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
                             CellPadding="1">

                             <FooterStyle BackColor="White" ForeColor="#000066" />
                             <RowStyle ForeColor="#000066" />

<Columns>

    <asp:TemplateField HeaderText="Select">

        <HeaderTemplate>

            <asp:CheckBox ID="chkSelectAll" runat="server" onclick="SelectAll(this.id)" />

        </HeaderTemplate>

        <ItemTemplate>

            <asp:CheckBox ID="chkSelect" runat="server" />

        </ItemTemplate>

    </asp:TemplateField>

    <asp:TemplateField HeaderText="PI temp">
        <ItemTemplate>
            <asp:Label ID="Label24" runat="server" Text='<%# Eval("pi_no") %>'></asp:Label>
            <asp:Label ID="LabelRUENO" runat="server" Text='<%# Eval("rue_no") %>'
                Visible="False"></asp:Label>
            <asp:Label ID="Labelcalid" runat="server" Text='<%# Eval("cal_id") %>'
                Visible="False"></asp:Label>
            <asp:Label ID="Labeltotalamt" runat="server" Text='<%# Eval("cal_id") %>'
                Visible="False"></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>

    </Columns>

                             <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                             <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                             <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />

</asp:GridView>

No comments:

Post a Comment

Print Only Grid View in ASP.net

ASP.net How to Print Only GridView < div id ="gridviewDiv" >   < asp:GridView ID ="gridViewToPri...