如何在datalist的外部得到绑定的单元格数据

curd0468 2008-06-03 04:31:32
现在有一个DataList1,有一个单元格数据id,我在DataList1里面用<%# Eval("id") %>可以显示,请问我怎样才能在其它的控件内得到这个值呢?
...全文
116 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
amandag 2008-06-03
  • 打赏
  • 举报
回复
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text=' <%# Eval("ID") %>'> </asp:Label> <br />
</ItemTemplate>
</asp:DataList>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Width="64px">查看</asp:LinkButton>
</div>


protected void LinkButton1_Click(object sender, EventArgs e)
{
Label l;
string str = string.Empty;
foreach (DataListItem item in DataList1.Items)
{
l = item.FindControl("Label1") as Label;
if (l != null)
{
str += l.Text;
}
}
Response.Write(str);
}
sxmonsy 2008-06-03
  • 打赏
  • 举报
回复
把值写到一个Label 中,
然后通过 ((Label)(e.Item.FindControl("label2"))).Text = (Label)(e.Item.FindControl("label2")).Text.ToString();
curd0468 2008-06-03
  • 打赏
  • 举报
回复
当然是有多少就显示多少了,可能我用id这个字段有点误导了吧,不好意思
amandag 2008-06-03
  • 打赏
  • 举报
回复
现在有一个DataList1,有一个单元格数据id,我在DataList1里面用 <%# Eval("id") %>可以显示,请问我怎样才能在其它的控件内得到这个值呢?
==
DataList中显示的多项数据,也就是将来显示的id会有多个,请问楼主打算显示那个?

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧