通过GridView的行循环和检查复选框控件 [英] Looping through GridView rows and Checking Checkbox Control

查看:136
本文介绍了通过GridView的行循环和检查复选框控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有一个GridView从一个学生表显示的数据,这是我的电网和相关的SqlDataSource;

I currently have a GridView which displays data from a Student Table, here is my Grid and associated SQLDataSource;

                      <asp:GridView ID="GridView2" 
                        style="position:absolute; top: 232px; left: 311px;" 
                            AutoGenerateColumns="false" runat="server"
                        DataSourceID="SqlDataSource4">
                        <Columns>
                            <asp:TemplateField>
                            <ItemTemplate >
                            <asp:CheckBox runat="server" ID="AttendanceCheckBox" />
                            </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                            <ItemTemplate>
                            <asp:Label ID="studentIDLabel" Text='<%# Eval("StudentID") %>' runat="server"></asp:Label>
                            </ItemTemplate>
                            </asp:TemplateField>                       
                            <asp:BoundField DataField="Name" HeaderText="Name" />
                        </Columns>
                     </asp:GridView>


                            的SelectCommand =SELECT [StudentID],[名] FROM [学生] WHERE CourseID = @CourseID>结果
                            
                                
                            

" SelectCommand="SELECT [StudentID], [Name] FROM [Student] WHERE CourseID = @CourseID ">

我在页面上一个按钮,当用户点击该按钮,通过我在GridView的每一行需要循环,然后找到复选框,然后我需要检查,如果该复选框被选中。如果复选框被选中,我需要在标签模板字段添加值到不同的数据库中的表。
我使用C#code。
任何帮助深表AP preciated,先谢谢了!

I have a button on the page which when the user clicks the button I need to loop through each row in the GridView, then find the CheckBox then I need to check if the checkbox is checked or not. If the checkbox is checked I need to add the value in the Label Template Field to a different table in the database. I am using C# Code. Any help is much appreciated, thanks in advance!

推荐答案

循环像

foreach (GridViewRow row in grid.Rows)
{
   if (((CheckBox)row.FindControl("chkboxid")).Checked)
   {
    //read the label            
   }            
}

这篇关于通过GridView的行循环和检查复选框控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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