取值的问题 你在控件的DataSource里遍历一遍不就行了么 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有两个办法:1.在你的数据源里面找你要的数据 比如你用的DataSet里面的某个Table里面找到你想要的数据2.找DataList里面找 即是你说的办法 foreach (DataListItem dli in this.DataList1.Items){Label label=(Label)dli.FindControl("ENo");//先找到你的控件string str=label.text.tostring().trim();} 你可以先把该字段(假设字段名称为Name)所有的值全部取出来,放在DataView1中,然后:String str="";DataView dv=DataView1;int num=dv.Count;for(int i=0;i<num;i++){ if(i==num-1) { str+=dv.Table.Rows[i]["Name"].ToString(); } else { str+=dv.Table.Rows[i]["Name"].ToString()+","; }} 读取的时候可以用://Items[0]表示第一行,Cells[0]表示第一列,Controls[0]表示Cell中的第一个控件(也只有这个控件可以用)HyperLink link = (HyperLink)DataGrid1.Items[0].Cells[0].Controls[0]);Response.Write(link.Text);至于模板列(TemplateColumn),当然也可以通过DataGrid1.Items[i].Cells[j].Controls[n]来获取,然后转换成原来的控件类型再操作,但是还有个更好的办法,就是用FindControl来查找控件。FindControl是System.Web.UI.Control的方法,可以根据子控件ID来查找子控件比如:假设DataGrid的某一列声明如下<asp:TemplateColumn> <ItemTemplate> <asp:TextBox Runat="server" ID="txtID" Text='<%# DataBinder.Eval(Container.DataItem,"au_id") %>'> </asp:TextBox> </ItemTemplate></asp:TemplateColumn>读取方法:TextBox txt = (TextBox)DataGrid1.Items[1].FindControl("txtID");Response.Write(txt.Text);注意:DataList中是没有Cell的 string a =((DataList)e.Item.Cells[11].Controls[1]).selectvalue(); 使用type=file获取文件路径,读取文件是报文件访问被拒绝 NET--使用replace将数字转换为汉字形式 asp.net iis5.0 无权访问页面 数据显示问题 求助:asp中表格隐藏 HELP:window.open()的问题 给你科头了,在线等。求人做一个文章发布系统。报酬详谈。 如何在ASP.NET的用户自定义类中实现dispose方法? dataset 中关于 sql语句中的 group by 请教:关于三层结构? DataGrid里面的数据怎样根据id倒序排列啊? 请教关于.net非托管代码内存管理问题.
1.在你的数据源里面找你要的数据 比如你用的DataSet里面的某个Table里面找到你想要的数据2.找DataList里面找 即是你说的办法
foreach (DataListItem dli in this.DataList1.Items)
{
Label label=(Label)dli.FindControl("ENo");//先找到你的控件
string str=label.text.tostring().trim();
}
String str="";
DataView dv=DataView1;
int num=dv.Count;
for(int i=0;i<num;i++)
{
if(i==num-1)
{
str+=dv.Table.Rows[i]["Name"].ToString();
}
else
{
str+=dv.Table.Rows[i]["Name"].ToString()+",";
}
}
//Items[0]表示第一行,Cells[0]表示第一列,Controls[0]表示Cell中的第一个控件(也只有这个控件可以用)
HyperLink link = (HyperLink)DataGrid1.Items[0].Cells[0].Controls[0]);
Response.Write(link.Text);
至于模板列(TemplateColumn),当然也可以通过DataGrid1.Items[i].Cells[j].Controls[n]来获取,然后转换成原来的控件类型再操作,但是还有个更好的办法,就是用FindControl来查找控件。
FindControl是System.Web.UI.Control的方法,可以根据子控件ID来查找子控件
比如:
假设DataGrid的某一列声明如下
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox Runat="server" ID="txtID" Text='<%# DataBinder.Eval(Container.DataItem,"au_id") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
读取方法:
TextBox txt = (TextBox)DataGrid1.Items[1].FindControl("txtID");
Response.Write(txt.Text);
注意:DataList中是没有Cell的