如何在网格视图中选中复选框 [英] How to make checkbox checked in grid view

查看:75
本文介绍了如何在网格视图中选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,其中1列是复选框,其他是任何名称,类。

如何使复选框选中为任意行(让2行)为true,如果我点击第二排任何地方...





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...


<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>

推荐答案

在后面的代码中执行此操作。



To do this in the code behind.

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





如果你想在Javascript中做一个关于CodeProject的好文章



使用Javascript在GridView中检查/打开CheckBox [ ^ ]


首先给出所有同名复选框的类名,然后在所有复选框的oncheckchange事件中调用Jqury / Javascript函数。在你的Jquery / Javascript中。设置检查/取消选中属性。
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.


这篇关于如何在网格视图中选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆