asp.net下如何实现下面的操作 本帖最后由 tianlebest 于 2010-06-17 11:29:41 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 都可以实现, 主要在于你自己的想法, HTML 的话 可以 添加一个 隐藏域,然后用JS 实现 获得选中的多选按钮的值,赋给隐藏域, 服务器控件 直接循环获得每一行的多选按钮 判断是否选中,然后 获得选中的多选按钮的值,有没有选中判断 累加的值是否为空 建议用html控件不过写JS费点劲,不过这样能减少服务器开销 HTML控件最好了,JS写起来也简单! 加上一个for(比如:for(i=0,i<=vector.size(),i++))循环,定义一个i 变量,利用索引的方式检索你需要的数据! 这跟服务器控件还是html控件没有直接的关系,但是这样的操作还是应该放到客户端来验证,毕竟比较快,如果要求比较严格的话,再服务器端再做一次判断也是可以的。 给你贴点代码吧,看代码最容易理解了:前台代码: <asp:CheckBox ID="infoCheck" runat="Server" Text='<%#DataBinder.Eval(Container.DataItem, "ID")%>' />后台代码: for (int i = 0; i < CompanyRep.Items.Count; i++) { CheckBox isChecked = (CheckBox)CompanyRep.Items[i].FindControl("infoCheck"); if (isChecked.Checked == true) { int ID = Convert.ToInt32(isChecked.Text); hycompanybll.delComByCompanyid(ID); } }其中CompanyRep是repeater控件,你可以在这里面做判断 //全选 protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { if (((CheckBox)sender).Checked) { for (int rowIndex = 0; rowIndex < gridShowClientInfos.Rows.Count; rowIndex++) { ((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked = true; } } else { for (int rowIndex = 0; rowIndex < gridShowClientInfos.Rows.Count; rowIndex++) { ((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked = false; } } } //反选 protected void checkedNoSelected_CheckedChanged(object sender, EventArgs e) { for (int rowIndex = 0; rowIndex < gridShowClientInfos.Rows.Count; rowIndex++) { if ((((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked == true)) { ((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked = false; } else { ((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked = true; } } } if (((CheckBox)sender).Checked) { //用户选择了 }else { //用户没有选择 } 以下代码测试通过for (int i = 0; i < GridView1.Rows.Count; i++) { string xxyy; CheckBox xxx = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); xxyy = ((HyperLink)GridView1.Rows[i].FindControl("hk2")).Text; if (xxx.Checked) { cs1.Text += xxyy + ","; } } if (cs1.Text == "") { ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "ToolTip", "alert('请选择方能比较!')", true); } else { //执行跳转等操作 cs1.Text = ""; } 如果用HTML控件的话,点执行的话肯定是先判断有没有选择的(这个已实现),但问题是怎么提交到服务器端去执行相关“删除。审核”等的操作啊 用得着吗?。。如果这全选反选都要去服务器交付,那么开销也太大了吧!用js就很简单的完成思路:1:var contraints=document.getElementById("你这个gridView的id号")2: var checkboxs=contraints.getElementsByTagName("Checkbox");3:for(var i=0;i<checkboxs.length;i++){ //这里面就判断checked选中或是没有选中的操作 } 用javascript就可以!能在客户端解决的就在客户端解决! 关于ajax 和 jquery 的问题,各位帮忙! asp.net mvc 奇怪的文件不存在错误 求助:关于asp.net中正则替换的问题 你还在用SqlParameter吗?早过时了 继承页的脚本写哪里? 如何在自动绑定的DataGrid中添加超链接列?如何控制? .NET compact framework是什么? 招ASP.NET开发人员 求:想实现每隔24小时系统自动执行一条SQL语句, C# decimal 值保存到 SQL decimal(9,4) 报错. 急!url链接问题。。。 iis问题
有没有选中判断 累加的值是否为空
但是这样的操作还是应该放到客户端来验证,毕竟比较快,
如果要求比较严格的话,再服务器端再做一次判断也是可以的。
前台代码:
<asp:CheckBox ID="infoCheck" runat="Server" Text='<%#DataBinder.Eval(Container.DataItem, "ID")%>' />后台代码:
for (int i = 0; i < CompanyRep.Items.Count; i++)
{
CheckBox isChecked = (CheckBox)CompanyRep.Items[i].FindControl("infoCheck");
if (isChecked.Checked == true)
{
int ID = Convert.ToInt32(isChecked.Text);
hycompanybll.delComByCompanyid(ID);
}
}其中CompanyRep是repeater控件,你可以在这里面做判断
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
{
for (int rowIndex = 0; rowIndex < gridShowClientInfos.Rows.Count; rowIndex++)
{
((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked = true;
}
}
else
{
for (int rowIndex = 0; rowIndex < gridShowClientInfos.Rows.Count; rowIndex++)
{
((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked = false;
}
}
}
//反选
protected void checkedNoSelected_CheckedChanged(object sender, EventArgs e)
{
for (int rowIndex = 0; rowIndex < gridShowClientInfos.Rows.Count; rowIndex++)
{
if ((((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked == true))
{
((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked = false;
}
else
{
((CheckBox)gridShowClientInfos.Rows[rowIndex].FindControl("checkSelected")).Checked = true;
}
}
}
{
//用户选择了
}
else
{
//用户没有选择 }
for (int i = 0; i < GridView1.Rows.Count; i++)
{
string xxyy;
CheckBox xxx = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
xxyy = ((HyperLink)GridView1.Rows[i].FindControl("hk2")).Text;
if (xxx.Checked)
{
cs1.Text += xxyy + ",";
}
}
if (cs1.Text == "")
{
ScriptManager.RegisterStartupScript(this.UpdatePanel3, this.GetType(), "ToolTip", "alert('请选择方能比较!')", true);
}
else
{
//执行跳转等操作
cs1.Text = "";
}
思路:
1:var contraints=document.getElementById("你这个gridView的id号")
2: var checkboxs=contraints.getElementsByTagName("Checkbox");
3:for(var i=0;i<checkboxs.length;i++){
//这里面就判断checked选中或是没有选中的操作
}