从数据绑定Gridview获取复选框
有没有办法检索 ASP.NET 中的数据绑定网格视图中是否选中了复选框字段?我可以使用 cell.Text
在 foreach
循环中检索所有其他单元格值。由于它是数据绑定的(到 ObjectDataSource),列和单元格没有显式设置的 ID,而且我似乎找不到可以让我知道单元格包含复选框或仅包含文本的属性。所有单元格的类型均为 DataControlFieldCell,因此我也无法根据类型进行检查。想法?
编辑:
foreach (GridViewRow row in report_gv.Rows)
{
data += "<TR>";
foreach (TableCell cell in row.Cells)
{
data += "<TD>" + cell.Text + "</TD>";
//If this is a checkbox (bit value from the DB) cell.Text isn't going to return anything
}
data += "</TR>";
}
Is there a way to retrieve whether a Checkbox field is checked in a databound gridview in ASP.NET? I can retrieve all other cell values in a foreach
loop with cell.Text
. Since it is databound (to an ObjectDataSource) the columns and cells don't have explicitly set IDs and I can't seem to find a property that would let me know the cell contains a checkbox or just text. All cells are of type DataControlFieldCell so I can't check based on type either. Thoughts?
EDIT:
foreach (GridViewRow row in report_gv.Rows)
{
data += "<TR>";
foreach (TableCell cell in row.Cells)
{
data += "<TD>" + cell.Text + "</TD>";
//If this is a checkbox (bit value from the DB) cell.Text isn't going to return anything
}
data += "</TR>";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以根据需要扩展此处理。
You can expand this to process however you need.
您可以在
GridViewItem
上使用FindControl
并按ItemTemplate
定义中的复选框 ID 进行搜索。FindControl GridView 上有很多示例,
例如查看以下内容:gridView 中的复选框
you can use
FindControl
on theGridViewItem
and search by the checkbox ID as you have it in theItemTemplate
definition.there are plenty of examples on FindControl GridView out there
for example check this out: checkBox in gridView
你可以做到的。但更简单的方法是转换为
,这将允许您为CheckBox
分配一个 ID。然后你的 foreach 就变成了:You can do it. But easier is to convert to a
<TemplateField>
, which will allow you to assign an ID to yourCheckBox
. Then your foreach goes:在 GridView.RowDataBound 事件您可以访问每行内的每个
复选框
。尝试这样的事情
In GridView.RowDataBound Event you can access each and every
checkbox
that inside each row.Try something like this