Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a gridview in which 1 column is of checkbox, and other are anything name,class.
how to make checkbox checked true for any row (let 2 row), if i click in 2nd row anywhere...


XML
<asp:GridView ID="GridView1" runat="server" DataKeyNames="studentid" AutoGenerateColumns="False" Width="100%"
                    HeaderStyle-HorizontalAlign="Left" HeaderStyle-Font-Bold="True"  HeaderStyle-Height="32px" >
                   <Columns>
                       <asp:TemplateField HeaderText="SNo">
                           <ItemTemplate>
                               <asp:Label ID="lblsno" runat="server" Text="<%# Container.DataItemIndex + 1 %>"></asp:Label>
                           </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField>
                           <HeaderTemplate>
                               <asp:CheckBox ID="ChkAll" Width="20px" runat="server"  AutoPostBack="true" OnCheckedChanged="ChkAll_CheckedChanged" />
                           </HeaderTemplate>
                           <ItemTemplate >
                               <asp:CheckBox ID="ChkIn"  runat="server" />
                           </ItemTemplate>
                       </asp:TemplateField>

                       <asp:TemplateField HeaderText="StudentID" SortExpression="Studentid" Visible="False">
                           <ItemTemplate>
                               <asp:Label ID="LbStudentid" runat="server" Text='<%# Bind("Studentid") %>'></asp:Label>
                           </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="AdmissionNo" SortExpression="AdmissionNo">
                           <ItemTemplate>
                               <asp:Label ID="Label2" runat="server" Text='<%# Bind("AdmissionNo") %>'></asp:Label>
                           </ItemTemplate>
                       </asp:TemplateField>
</grid view>
Posted
Comments
Snesh Prajapati 20-Mar-14 8:38am    
do you want to use JavaScript or jQuery?
CHill60 20-Mar-14 8:41am    
I guess VB.NET in the code behind given the tags
Snesh Prajapati 20-Mar-14 8:43am    
Sorry I don't have much idea about VB.NET.

To do this in the code behind.

VB
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
    If e.CommandName = "check" Then
        'Enable Editing on the GridView
        GridView1.EditIndex = GridView1.SelectedIndex
        'Assign value to the row selected
        Dim index As Integer = Convert.ToInt32(e.CommandArgument)
        'Assign selected gridview row
        Dim checkBox As CheckBox = GridView1.Rows(index).FindControl("ChkAll")

        checkBox.Checked = true 'or false or whatever based on your command.
    End If
End Sub


If you want to do it in Javascript there is a nice article on CodeProject

Check/uncheck CheckBox in a GridView using Javascript[^]
 
Share this answer
 
first you give the class name of all the checkbox of same name then call a Jqury /Javascript function in oncheckchange event of all the checkbox . In your Jquery /Javascript . Set the Check/Uncheck Attribute.
 
Share this answer
 

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