关于repeater绑定数组后的取值问题。(asp.net c#)
请问repeater绑定数组后,在网页里可用<%#GetDataItem()%>取得值,现在我想在ItemDataBound事件中取到数组的值,请问代码如何写呢?谢谢...
请问repeater绑定数组后,在网页里可用<%#GetDataItem() %>取得值,现在我想在ItemDataBound事件中取到数组的值,请问代码如何写呢?谢谢
展开
展开全部
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
string value = e.Item.DataItem.ToString();//在这里活动数据里的值
}
完整代码:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.Repeater1.DataSource = new string[] { "a", "b", "c" };
this.Repeater1.DataBind();
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
string value = e.Item.DataItem.ToString();//在这里活动数据里的值
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate><%# GetDataItem() %></ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
{
string value = e.Item.DataItem.ToString();//在这里活动数据里的值
}
完整代码:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.Repeater1.DataSource = new string[] { "a", "b", "c" };
this.Repeater1.DataBind();
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
string value = e.Item.DataItem.ToString();//在这里活动数据里的值
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate><%# GetDataItem() %></ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询