如果不在datalist中添加linkbutton
那么怎么通过checkbox和一个不在datalist中的button来选中选定行并取值?
中间代码不知道咋写=.= protected void Button3_Click(object sender, EventArgs e)
{
foreach (DataListItem dli in this.DataList1.Items)
{
CheckBox cb = (CheckBox)dli.FindControl("check");
if (cb.Checked == true)
{
}
} }
那么怎么通过checkbox和一个不在datalist中的button来选中选定行并取值?
中间代码不知道咋写=.= protected void Button3_Click(object sender, EventArgs e)
{
foreach (DataListItem dli in this.DataList1.Items)
{
CheckBox cb = (CheckBox)dli.FindControl("check");
if (cb.Checked == true)
{
}
} }
解决方案 »
- 为什么C#写的ftp反应很慢,打开文件需要挺长一段时间的等待(比用网上邻居还要慢),其他语言写速度(访问和下载文件)会快一些吗?
- 求一个C#函数,传一个int数,
- 定义枚举 怎么在Grid中显示出来~
- 同时读网卡和串口数据
- 怎么获取DATADRID每行的数据,并写入数据库中!!!!高手
- c#打开其他exe,提示:不能打开文件
- 初学C#问个简单的问题
- 用C#开发一个界面程序。要实现单位(编号、名称、备注)和人员(工号、姓名、性别、年龄、职业)的管理,要求单位和人员放入一个TreeView中,结构采用MVC 结构,代码中需要用到ArrayList,hashtable等,数据库使用sqlserver
- 呵呵,又换号了,再给200分,问两个关于DataGridView的具体问题。再次感谢刚才帮助和帮顶的朋友
- 统计玩家拥有城池的时间
- C#如何取到这样数字:0911***年月,001开始?
- private bool [,] Arr=new bool[5,5];
ArrayList username = new ArrayList();
protected void Button3_Click(object sender, EventArgs e)
{
foreach (DataListItem dli in this.DataList1.Items)
{
CheckBox cb = (CheckBox)dli.FindControl("check");
if (cb.Checked == true)
{
Label Lab=(Label)this.DataList1.FindControl("username");
username.Add(Lab.Text.ToString()); }
} }这个也取不出值,有什么问题呢?
foreach (DataListItem dli in this.DataList1.Items)
{
CheckBox cb = (CheckBox)dli.FindControl("check");
if (cb.Checked == true)
{
Label Lab=(Label)dli.FindControl("username");
username.Add(Lab.Text.ToString()); }
}
现在新问题也来了 就是根本不管 CheckBox 选没选中都进不了if语句
这个是什么问题
就是进不去if语句 下面这个全选CheckBox倒是可以执行 很是奇怪啊.. protected void Button1_Click(object sender, EventArgs e)
{
if (this.Button1.Text == "全选")
{
foreach (DataListItem dli in this.DataList1.Items)
{
CheckBox cb = (CheckBox)dli.FindControl("check");
cb.Checked=true;
}
this.Button1.Text = "全部取消";
}
else
{
foreach (DataListItem dli in this.DataList1.Items)
{
CheckBox cb = (CheckBox)dli.FindControl("check");
cb.Checked = false;
}
this.Button1.Text = "全选";
}
}
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{
//指定datalist数据源并绑定
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class cuser_UserC : System.Web.UI.Page
{
ArrayList username = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
BingData();
}
public void BingData()
{
DataAccess.Class1 dataClass = new DataAccess.Class1();
this.DataList1.DataSource = dataClass.getTable(Common.Class1.sql_user, Common.Class1.table_user).Tables[0].DefaultView;
this.DataList1.DataBind();
} protected void Button3_Click(object sender, EventArgs e)
{
foreach (DataListItem dli in this.DataList1.Items)
{
CheckBox cb = (CheckBox)dli.FindControl("check");
if (cb.Checked == true)
{
Label Lab=(Label)dli.FindControl("username");
username.Add(Lab.Text.ToString());
}
} }
protected void Button1_Click(object sender, EventArgs e)
{
if (this.Button1.Text == "全选")
{
foreach (DataListItem dli in this.DataList1.Items)
{
CheckBox cb = (CheckBox)dli.FindControl("check");
cb.Checked=true;
}
this.Button1.Text = "全部取消";
}
else
{
foreach (DataListItem dli in this.DataList1.Items)
{
CheckBox cb = (CheckBox)dli.FindControl("check");
cb.Checked = false;
}
this.Button1.Text = "全选";
}
}
前台 <asp:DataList ID="DataList1" runat="server" Height="167px" Width="754px"
CaptionAlign="Left">
<ItemStyle Font-Size="X-Small" />
<HeaderStyle
Font-Names="宋体" Font-Size="Smaller" HorizontalAlign="Center"
VerticalAlign="Middle" />
<HeaderTemplate>
<table><tr>
<td align="center" dir="ltr"
style="width:60px; font-family: 宋体; font-size: smaller">
选择</td>
td align="center" style="width:80px; font-family: 宋体; font-size: smaller">
用户名</td>
<td align="center" style="width:100px; font-family: 宋体; font-size: smaller">
设备号</td>
<td align="center" style="width:100px; font-family: 宋体; font-size: smaller">
设备数量</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:CheckBox ID="check" runat="server"/>
</td>
<td><asp:Label ID="username" RUNAT="server"
TEXT= <%#DataBinder.Eval(Container.DataItem,"username") %>></asp:Label>
<td>
<asp:Label ID="deviceID" RUNAT="server"
TEXT= <%#DataBinder.Eval(Container.DataItem, "deviceID")%>></asp:Label>
</td>
<td><asp:Label ID="deviceNumber" RUNAT="server"
TEXT= <%#DataBinder.Eval(Container.DataItem, "deviceNumber")%>></asp:Label>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
{
if (!IsPostBack)
{ BingData();
}
}