1.datalist中放入1个checkbox,共7条数据,也就是显示7个checkbox,如何判断只选中其中的4个?
2.如何得到当前所选中的checkbox的值?
2.如何得到当前所选中的checkbox的值?
解决方案 »
- winfrom中如何显示网页的其中一个部分
- 弄了几天搞不定啊:TcpClient传入的IP地址是无效的IP,用户界面停止响应状态如何解决
- 怎样连接到远程主机?
- 求解决方法!
- webservice的问题,菜鸟小题,要分的来。
- 泛型List<T>不能继承问题。
- 有高手做过用C#访问InSQL实时数据库的么.
- 请问repeater要怎么显示这样,急啊
- 急急!!!求救高手!!vs2005c#如何打印窗体上的所有内容
- 就30分了:AcceptTcpClient方法用了之后为什么一定要关闭(只是理论问题欢迎交流)
- Checkboxlist 从数据库读出数据,如何判断有几条?
- 关于Dictionary的问题。
//checkbox验证
public bool IsCHBValid()
{
bool flag=false;
string sort="";
foreach(ListItem i in this.CheckBoxList1.Items)
{
if(i.Selected==true)
{
sort+=i.Value;
}
} if( sort!="" )
{
flag=true;
}
return flag;
}
protected void Button1_Click(object sender, EventArgs e)
{
int a=0;
for (int i = 0; i < DataList1.Items.Count; i++)
{
if (((CheckBox)DataList1.Items[i].FindControl("CheckBox1")).Checked==true)
a += 1;
}
if(a==4)
Response.Write("你选中了4项!!");
}
if(!status)
{
this.checkbox1.checked=false;
}
在类中添加如下代码private bool CheckStatus()
{
int a=0;
for (int i = 0; i < DataList1.Items.Count; i++)
{
if (((CheckBox)DataList1.Items[i].FindControl("CheckBox1")).Checked==true)
a += 1;
}
if(a==4)
return false;
return ture; }
<asp:HiddenField ID="commentid" Value='<%#Eval("commentid")%>' runat="server"/>
//删除选中的数据。可全删除。全选根据ID删除
protected void delWriteLog_Click(object sender, ImageClickEventArgs e)
{
sqlt.SetSQLBeginTrans();
try
{
for (int i = 0; i < rpMyReceiveComment.Items.Count; i++)
{
CheckBox CB = (CheckBox)rpMyReceiveComment.Items[i].FindControl("single_Chk");
if (CB.Checked == true)
{
string delID = ((HiddenField)rpMyReceiveComment.Items[i].FindControl("commentid")).Value;
cookies = Request.Cookies["UserCookies"];
if (cookies != null)
{
int uid = int.Parse(cookies["User_Uid"].ToString());//
sqlt.Operate("update a set a.delstate=1 from dbo.space_MyComments a inner join dbo.space_MyReleased b on a.logid=b.logid where a.commentid=" + delID + " and b.uid=" + uid);
}
}
} sqlt.SetSQLCommitTrans(); sqlt.ConClose();
}
catch
{
sqlt.SetSQLRollBack(); sqlt.ConClose(); base.MessageBox("00006", null);
}
this.PageFen();
}
{
CheckBox CB = (CheckBox)rpMyReceiveComment.Items[i].FindControl("single_Chk");
if (CB.Checked == true)
{
string delID = ((HiddenField)rpMyReceiveComment.Items[i].FindControl("commentid")).Value;//选中的四项值
}
}
foreach ( DataListItem item in DataList1.Items )
{
CheckBox chk = (CheckBox) item.FindControl("CheckBox1");
if(chk.Checked)
{
}
}
一般的错误是id错!!你看是否打错了!!
if (((CheckBox)DataList1.Items[i].FindControl("CheckBox1")).Checked==true)
{ for (int i = 0; i < shu; i++)
{
if (CheckBoxList2.Items[i].Selected)
{
s1 = s1 + CheckBoxList2.Items[i].Text + ","; } }
Label10.Text = s1 ;
Label6.Text = Label10.Text + Label11.Text;
string str1 = Label6.Text.ToString();
string[] astr = str1.Split(',');
intCnt = astr.Length - 1;
if (intCnt > shu)
{
Response.Write("<script>alert('最多只能选"+shu+"个')</script>");
Response.AddHeader("refresh", "0");
}
} public void panduan()
{
for (int i = 0; i < shu; i++)
{
if (CheckBoxList2.Items[i].Selected)
{
s1 = s1 + CheckBoxList2.Items[i].Text + ","; } }
Label10.Text = s1;
Label6.Text = Label10.Text + Label11.Text;
string str1 = Label6.Text.ToString();
string[] astr = str1.Split(',');
intCnt = astr.Length - 1;
if (intCnt > shu)
{
Response.Write("<script>alert('最多只能选" + shu + "个')</script>");
Response.AddHeader("refresh", "0");
}
}