GridView的CheckBox列选择及多参数传递三步搞定
程序员文章站
2024-03-05 18:40:07
1、gridview的列设置 复制代码 代码如下:
1、gridview的列设置
<asp:templatefield headerstyle-cssclass="check" itemstyle-cssclass="check">
<headertemplate>
<input type="checkbox" onclick="selectall(this)" />
全选
</headertemplate>
<itemtemplate>
<input name="chkidcardnum" type="checkbox"
value="<%# eval("pid") %>$<%# eval("identitycard")%>$<%# eval("pname")%>"
<%# "1" == eval("iscoulddelete").tostring()?"disabled='disabled'":""%> />
</itemtemplate>
</asp:templatefield>
<asp:templatefield visible="true" headertext="删除">
<itemtemplate>
<asp:linkbutton id="lbtndelete" commandname="lbtndelete" runat="server" text="删除档案"
commandargument='<%# eval("pid") +"$"+ eval("identitycard")%>'
onclientclick="return confirm('确认删除?');"
visible='<%# eval("termination").tostring()=="1" ? false : true %>' />
</itemtemplate>
</asp:templatefield>
2、全选的js处理
function selectall(myself) {
var ostate = myself.checked;
var checkboxes = document.getelementsbyname("chkidcardnum"); //获取input组
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].disabled) {
} else {
checkboxes[i].checked = ostate; //选择值
}
}
}
3、后台对所选值的获取
var selectedids = request.params["chkidcardnum"].split(',');
if (selectedids.length == 0)
return;
//int[] msgids = array.convertall<string, int>(selectedids, s => int.parse(s));
int[] ids = selectedids.select(t => int.parse(t.split('$')[0])).toarray();
string[] cards = selectedids.select(t => t.split('$')[1]).toarray();
复制代码 代码如下:
<asp:templatefield headerstyle-cssclass="check" itemstyle-cssclass="check">
<headertemplate>
<input type="checkbox" onclick="selectall(this)" />
全选
</headertemplate>
<itemtemplate>
<input name="chkidcardnum" type="checkbox"
value="<%# eval("pid") %>$<%# eval("identitycard")%>$<%# eval("pname")%>"
<%# "1" == eval("iscoulddelete").tostring()?"disabled='disabled'":""%> />
</itemtemplate>
</asp:templatefield>
<asp:templatefield visible="true" headertext="删除">
<itemtemplate>
<asp:linkbutton id="lbtndelete" commandname="lbtndelete" runat="server" text="删除档案"
commandargument='<%# eval("pid") +"$"+ eval("identitycard")%>'
onclientclick="return confirm('确认删除?');"
visible='<%# eval("termination").tostring()=="1" ? false : true %>' />
</itemtemplate>
</asp:templatefield>
2、全选的js处理
复制代码 代码如下:
function selectall(myself) {
var ostate = myself.checked;
var checkboxes = document.getelementsbyname("chkidcardnum"); //获取input组
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].disabled) {
} else {
checkboxes[i].checked = ostate; //选择值
}
}
}
3、后台对所选值的获取
复制代码 代码如下:
var selectedids = request.params["chkidcardnum"].split(',');
if (selectedids.length == 0)
return;
//int[] msgids = array.convertall<string, int>(selectedids, s => int.parse(s));
int[] ids = selectedids.select(t => int.parse(t.split('$')[0])).toarray();
string[] cards = selectedids.select(t => t.split('$')[1]).toarray();