zoukankan
html css js c++ java
获取CheckBox在GridView模板列中的值
aspx:
<
asp:GridView
ID
="gvdeptusers"
runat
="server"
DataKeyNames
="id"
AutoGenerateColumns
="False"
Width
="100%"
ShowHeader
="False"
OnRowDataBound
="gvdeptusers_RowDataBound"
>
<
Columns
>
<
asp:BoundField
DataField
="names"
>
<
ItemStyle
Width
="8%"
HorizontalAlign
="Center"
/>
</
asp:BoundField
>
<
asp:BoundField
DataField
="deptname"
>
<
ItemStyle
Width
="10%"
HorizontalAlign
="Center"
/>
</
asp:BoundField
>
<
asp:TemplateField
>
<
ItemTemplate
>
<
asp:HiddenField
ID
="hdtype"
runat
="server"
Value
='<%#
Eval("user_classid") %
>
' />
<
asp:CheckBox
ID
="cbusers"
Text
='<%#
Eval("username") %
>
' runat="server" />
</
ItemTemplate
>
</
asp:TemplateField
>
</
Columns
>
</
asp:GridView
>
cs:
string
idStr
=
""
;
foreach
(GridViewRow row
in
this
.gvdeptusers.Rows)
{
if
(((CheckBox)row.FindControl(
"
cbusers
"
)).Checked
==
true
)
{
idStr
+=
this
.gvdeptusers.DataKeys[row.RowIndex].Value
+
"
<br>
"
;
}
}
Response.Write(idStr);
Response.End();
绑定选定值:
protected
void
gvdeptusers_RowDataBound(
object
sender, GridViewRowEventArgs e)
{
int
strid
=
e.Row.RowIndex;
CheckBox cbusers
=
(CheckBox)e.Row.FindControl(
"
cbusers
"
);
if
(cbusers
!=
null
)
{
string
strhdtype
=
((HiddenField)e.Row.FindControl(
"
hdtype
"
)).Value;
if
(strhdtype
!=
"
1
"
&&
strhdtype
!=
"
8
"
) cbusers.Checked
=
true
;
}
}
很简单的代码,怕忘记所以记录于此。
查看全文
相关阅读:
【LeetCode】1. Two Sum
框架
表单
JavaScript写计算器
导航下拉菜单代码
注册表代码
简易表格代码
HTML (超文本标记语言)
PHP学习目标
升级python到最新2.7.13
原文地址:https://www.cnblogs.com/cnaspnet/p/725425.html
最新文章
静态传递闭包
树状数组求逆序对
图论之tarjan缩点
离散化
整体二分
日常迷信(滑稽)
POJ2318 TOYS(叉积判断点与直线的关系+二分)
HDU1175 连连看(DFS)
关于css中伪类及伪元素的总结
js中offsetHeight、clientHeight、scrollHeight等相关属性区分总结
热门文章
关于js原型的面试题
div css背景图片不显示
css背景图与html插入img的区别
【LeetCode】423. Reconstruct Original Digits from English
【LeetCode】463. Island Perimeter
BitSort
【LeetCode】434. Number of Segments in a String
【LeetCode】419. Battleships in a Board
【LeetCode】3. Longest Substring Without Repeating Characters
【LeetCode】2.Add Two Numbers
Copyright © 2011-2022 走看看