当前位置: 代码迷 >> ASP.NET >> CheckBox 多选框怎样取值解决办法
  详细解决方案

CheckBox 多选框怎样取值解决办法

热度:9362   发布时间:2013-02-25 00:00:00.0
CheckBox 多选框怎样取值
<ItemTemplate>
  <tr>
  <td width="59" height="25" align="center" bgcolor="#FFFFFF"><%#(AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize+(Container.ItemIndex + 1)%></td>
  <td width="147" align="center" bgcolor="#FFFFFF"><%#Eval("admin") %></td>
  <td width="129" align="center" bgcolor="#FFFFFF"><%#Eval("isadmin") %></td>
  <td width="129" align="center" bgcolor="#FFFFFF"><a href="Modify_Admin.aspx?id=<%#Eval("id")%>">修改</a></td>
  <td width="130" align="center" bgcolor="#FFFFFF"><%#Eval("id") %><input type="checkbox" id="chkItem" value=<%#Eval("id")%>> </td>
  </tr>
  </ItemTemplate>
<FooterTemplate> 
  <tr>
  <td height="25" colspan="5" bgcolor="#FFFFFF" align="center"><asp:Button ID="Button1" runat="server" Text="删除所选中的" OnClick="Delet_Admin" /><asp:CheckBox ID="chkHeader" runat="server" AutoPostBack="False" onclick="SelectAll(this);"/></td>
  </tr>
  </table>
  </FooterTemplate>



在删除时怎样取到勾选的值。
小弟在线跪求 急急急

------解决方案--------------------------------------------------------
C# code
        CheckBoxList cbl = new CheckBoxList();        Response.Write("选中的如下:");        for (int i = 0; i < cbl.Items.Count; i++)        {            if (cbl.Items[i].Selected)                Response.Write(cbl.Items[i].Value + "<br/>");        }
------解决方案--------------------------------------------------------
string str = "";
str = Request.Form.Get("checkboxname");
string Sql = "UPDATE tb SET [isDelete] = 1 WHERE [Id] in (" + str + ")";

前台,你那个加个name属性~
<input type="checkbox" id="checkboxname" name="checkboxname" value='<%# DataBinder.Eval(Container.DataItem, "Id")%>' />
------解决方案--------------------------------------------------------
JScript code
var strValue ="" //全局变量function selectChk(checkboxID){    if(document.getElementById(checkboxID).checked)    {        strValue += checkboxID+ ",";    }    else    {        strValue = strValue.replace(checkboxID+",","");    }}  在checkBox 的 onclick事件
  相关解决方案