Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i can select and deselect checkboxes in gridview but now i ned to find the control of checkbox which are checked in gridview by using jquery
Posted

Hi...
See this one for all check box checked.
In Script:
XML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('[id*=chkHeader]').click(function () {
                $("[id*='chkChild']").attr('checked', this.checked);
            });
        });
               </script>

In Body:
XML
<asp:GridView ID="gvUserInfo" runat="server" Width="561px" AutoGenerateColumns="False">
        <HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
        <Columns>
        <asp:TemplateField><HeaderTemplate>
        <asp:CheckBox ID="chkHeader" runat="server" />
        </HeaderTemplate>
        <ItemTemplate>
        <asp:CheckBox ID="chkChild"  runat="server"/>
        </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="Id">
                <ItemTemplate>
                <asp:Label ID="lblId" runat="server" Text='<%# Eval("Id") %>'/>
                </ItemTemplate>
                </asp:TemplateField>

In Button.cs:
C#
foreach (GridViewRow gvrow in gvUserInfo.Rows)
            {
                //Finiding checkbox control in gridview for particular row
                CheckBox chkdelete = (CheckBox)gvrow.FindControl("chkChild");

                //Condition to check checkbox selected or not
                if (chkdelete.Checked)
                {
                    string UserName = ((Label)gvUserInfo.Rows[gvrow.RowIndex].FindControl("lblUserName")).Text;
 }
            }
            Label1.Text = UserName;
        }

Like that, find checked values in gridview.
Thank u.
 
Share this answer
 
Comments
Deenuji 12-Jul-13 3:36am    
gud +5
you need a onclick attribute and one hidden field
taken one hidden field
ASP.NET
<asp:hiddenfield id="setup_id" runat="server" value="" xmlns:asp="#unknown" />


and take one checkbox

XML
<asp:checkbox id="chk_centrelink_pensions" runat="server" onclick="getchecked(this);" xmlns:asp="#unknown" />


now in javascript

JavaScript
function getchecked(aa)
{
   $('setup_id').value=aa.id;
}

so now in hiddenfield checked checkbox value will be stored and you can use it .....
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900