在GridView里面添加CheckBox,如何实现哪一行被选中
2009-04-13 21:29
806 查看
一:添加CheckBox
<asp:GridView>
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
<ItemTemplate>
<asp:CheckBox ID="CheckBox" runat="server" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Code" HeaderText="学号" SortExpression="Code">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
</asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="姓名">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
</asp:BoundField>
<asp:BoundField DataField="SchoolName" HeaderText="所在学校">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
</asp:BoundField>
<asp:BoundField DataField="Email" HeaderText="E-mail">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
</asp:BoundField>
</Columns>
</asp:GridView>
二:查看哪一行的CheckBox被选中
foreach(GridViewRow row in this.StudentGridView.Rows)
{
Control ctrl = row.FindControl("CheckBox");
if ((ctrl as CheckBox).Checked)
{
TableCellCollection cell = row.Cells;
string studentCode = cell[1].Text;
}
}
<asp:GridView>
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
<ItemTemplate>
<asp:CheckBox ID="CheckBox" runat="server" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Code" HeaderText="学号" SortExpression="Code">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
</asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="姓名">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
</asp:BoundField>
<asp:BoundField DataField="SchoolName" HeaderText="所在学校">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
</asp:BoundField>
<asp:BoundField DataField="Email" HeaderText="E-mail">
<ItemStyle HorizontalAlign="Center" Height="35px" Width="720px"/>
</asp:BoundField>
</Columns>
</asp:GridView>
二:查看哪一行的CheckBox被选中
foreach(GridViewRow row in this.StudentGridView.Rows)
{
Control ctrl = row.FindControl("CheckBox");
if ((ctrl as CheckBox).Checked)
{
TableCellCollection cell = row.Cells;
string studentCode = cell[1].Text;
}
}
相关文章推荐
- 在GridView里面添加CheckBox,如何实现哪一行被选中
- 如何在GridView中添加CheckBox控件列,添加删除确认对话框
- iOS 自定义UITableViewCell上添加UIButton按钮如何确定点击了哪一行,代码块实现
- C# GridView列头添加CheckBox控件实现全选功
- GridView控件中添加CheckBox控件,并且实现选择、全选和反选
- Gridview如何实现敲回车进入下一行,或者用方向键在不同的行之间切换?
- 检测GridView里面的CheckBox是否被选中
- GridView模板列中添加CheckBox 实现全选、删除
- 笔记,GridView点击添加背景,类似checkbox效果的实现
- 如何实现点击GridView中一个图片后,如何传递至一个新的Activity中的imageview里面显示?
- 如何判断GridView控件的某一行是否被选中
- GridView 添加checkBox 实现全选功能
- Android里ListView里面添加CheckBox实现多选。
- Gridview中的添加CheckBox实现全选
- iOS 自定义UITableViewCell上添加UIButton按钮如何确定点击了哪一行,代码块实现
- JavaScript实现GridView中添加CheckBox列(全选与否)
- 在FTE的project里面,如何在一个没有Toolbar的screen添加Toolbar来实现快捷操作
- 如何判断GridView控件的某一行是否被选中
- Android里ListView里面添加CheckBox实现单选。
- listview里面添加checkbox实现单选,多选