asp.net中怎样获取repeater中的数据

asp.net中怎样获取repeater中的数据,第1张

aspnet中获取repeater中的数据的方法是使用DataBinderEval循环获取。

Repeater 控件用于显示重复的项目列表,这些项目被限制在该控件。Repeater 控件可被绑定到数据库表、XML 文件或者其他项目列表。

以下的完整的读取Repeater的值的方法:

<%@ Import Namespace="SystemData" %>

<%@ Import Namespace="SystemDataSqlClient" %>

<html>

<script language="C#" runat="server">

void Page_Load(Object sender, EventArgs e)

{

// 创建连接到pubs数据库

// 访问本地的数据库

SqlConnection myConnection = new SqlConnection("server=localhost;" +

"database=pubs;Trusted_Connection=Yes");

// 使用select语句查询title表中的所有记录

SqlDataAdapter myCommand = new SqlDataAdapter("SELECT FROM" +

" Titles", myConnection);

// 创建并且填充结果集

DataSet ds = new DataSet();

myCommandFill(ds);

// 绑定数据到MyRepeater

MyRepeaterDataSource = ds;

MyRepeaterDataBind();

}

</script>

<%-- 循环读取 MyRepeater中的数据--%>

<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">

<ASP:Repeater id="MyRepeater" runat="server">

<HeaderTemplate>

<Table width="100%" style="font: 8pt verdana">

<tr style="background-color:DFA894">

<th>

Title

</th>

<th>

Title ID

</th>

<th>

Type

</th>

<th>

Publisher ID

</th>

<th>

Price

</th>

</tr>

</HeaderTemplate>

<ItemTemplate>

<tr style="background-color:FFECD8">

<td>

<%# DataBinderEval(ContainerDataItem, "title") %>

</td>

<td>

<%# DataBinderEval(ContainerDataItem,"title_id") %>

</td>

<td>

<%# DataBinderEval(ContainerDataItem, "type") %>

</td>

<td>

<%# DataBinderEval(ContainerDataItem, "pub_id") %>

</td>

<td>

<%# DataBinderEval(ContainerDataItem,

"price", "{0:c}") %>

</td>

</tr>

</ItemTemplate>

<FooterTemplate>

</Table>

</FooterTemplate>

</ASP:Repeater>

</body>

</html>

这个很简单的,我告诉你:

foreach (RepeaterItem RPItem in thisRepeNewsItems)

{

CheckBox Check = (CheckBox)RPItemFindControl("repeater 中循环的checkbox的ID");

if (!CheckChecked)

{

//处理CheckBox

ChBText

}

}

在rep中放一组按钮

给绑定值

<asp:ImageButton ID="rep_Img" runat="server" ImageUrl="#" CommandArgument='<%#Eval("data") %>' CommandName="cmd_click" />

在再rep项命令事件中写代码

protected void rep_DataBase_ItemCommand(object source, RepeaterCommandEventArgs e)

{

if (eItemItemType == ListItemTypeItem || eItemItemType == ListItemTypeAlternatingItem)

{

if (eCommandName == "cmd_click")

{

ResponseWrite("<script>alert('" + eCommandArgumentToString() + "')</script>");

}

}

}

这样就可以了 还有什么不明白的可以hi我

以上就是关于asp.net中怎样获取repeater中的数据全部的内容,包括:asp.net中怎样获取repeater中的数据、asp.net里我想获取Repeater里的所有CheckBox,id肯定不唯一,请问要怎么获取啊、我用repeater控件绑定了一组图,我想通过点击事件获取其中一张图片的id 值。我不知道怎么做谁能告诉我等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/9557205.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存