中继器绑定,具有一定的数据的操作 [英] repeater databinding , with manipulation of certain data
问题描述
下面是我的中继器code,一切工作正常,但我有一个问题:
在结束后的<跨度类=txsources>来源:< / SPAN>
,我希望把从中继链路,在数据源背后code具有包含链接的另一个领域,但这鳍这一领域,该消息人士编写,并用分离;
,如:链接1,链接2; LINK3 ....
所以,我一直在说写在背后code函数做这个工作......在其 onitemdatabound
中的中继器,我该怎么办它,什么应该BW写的功能?为了能够将它们分开的;
,并把它们作为链接
< ASP:直放站=服务器ID =rptArticleContent>
<&ItemTemplate中GT;
&所述; TR>
< TD WIDTH =365VALIGN =顶align =left级=的BodyContent的bgcolor =#FFFFFF>
< DIV>
&所述H 2类=H2>
< ASP:标签=服务器ID =DSDS> <%#的eval(标题)%GT;< / ASP:标签>
< / H>
< DIV CLASS =文章体>
< DIV CLASS =文章图像>
<%#的eval(图像)%GT;
< / DIV>
<%#的eval(说明)%GT;
< / DIV>
< DIV CLASS =horizontal_dotted_line1ALIGN =右>
&所述; A HREF =#顶>>>返回顶部< / A>< / DIV>
<跨度类=txsources>来源:< / SPAN>< A HREF =#目标=_空白>链接1< / A>
| < A HREF =#目标=_空白>链接2'; / A> | < A HREF =#目标=_空白>链接3'; / A>
| < A HREF =#目标=_空白>链接4℃; / A> | < A HREF =#目标=_空白>链接5℃; / A>
| < A HREF =#目标=_空白>链接6 LT; / A>< / DIV>
< / TD>
< / TR>
< / ItemTemplate中>
< / ASP:直放站>
我想创建一个< ASP:文字/>
的<跨度类=txsources>来源:< / SPAN>
这将被用来包含链接
在您的code的背后,内的ItemDataBound,你可以做类似如下:
保护小组rptArticleContent_ItemDataBound(BYVAL发件人为对象,BYVAL E上System.Web.UI.WebControls.RepeaterItemEventArgs)处理rptArticleContent.ItemDataBound 选择案例e.Item.ItemType
案例ListItemType.Item,ListItemType.AlternatingItem 昏暗的链接作为字符串= e.Item.DataItem(链接)
昏暗LinksStr作为字符串()= Links.Split(;) 昏暗LTL作为文字= e.Item.FindControl(零担)
昏暗公司作为整数= 1
对于每个项目作为字符串在LinksStr
Ltl.Text + =的String.Format(< A HREF ={0}>链接{1}< / A>中,项目公司)
公司+ = 1
下一个 结束选择结束小组
C#相当于code:
保护无效rptArticleContent_ItemDataBound(对象发件人,System.Web.UI.WebControls.RepeaterItemEventArgs E)
{
开关(e.Item.ItemType){
案例ListItemType.Item:
案例ListItemType.AlternatingItem: 字符串链接= e.Item.DataItem(链接);
字符串[] = LinksStr Links.Split(); 文字LTL = e.Item.FindControl(零担);
INT公司= 1;
的foreach(在LinksStr字符串项){
Ltl.Text + =的String.Format(< A HREF ={0}>链接{1}< / A>中,项目公司);
公司+ = 1;
}
打破;
}}
Below is my repeater code, everything is working fine, but I have a problem:
At the end after the <span class="txsources">Sources: </span>
, I want put the links from the repeater, In the code behind the data source has another field that contains the links, but this fin this field, the sources are written and separated with a ;
, as : link1;link2;link3....
So I've been told to write a function in code behind that do this job...and its onitemdatabound
in the repeater, how can I do it, and what should bw written in that function? To be able to split them on the ;
and put them as links.
<asp:Repeater runat="server" ID="rptArticleContent">
<ItemTemplate>
<tr>
<td width="365" valign="top" align="left" class="bodyContent" bgcolor="#FFFFFF">
<div>
<h2 class="h2">
<asp:Label runat="server" ID="dsds"> <%#Eval("Title") %></asp:Label>
</h2>
<div class="article-body">
<div class="Article-image">
<%#Eval("Image") %>
</div>
<%#Eval("Description") %>
</div>
<div class="horizontal_dotted_line1" align="right">
<a href="#top">>> Back to top</a></div>
<span class="txsources">Sources: </span><a href="#" target="_blank">Link 1</a>
| <a href="#" target="_blank">Link 2</a> | <a href="#" target="_blank">Link 3</a>
| <a href="#" target="_blank">Link 4</a> | <a href="#" target="_blank">Link 5</a>
| <a href="#" target="_blank">Link 6</a></div>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
I would create an <asp:Literal />
control after the <span class="txsources">Sources: </span>
which would be used to contain the links.
In your code behind, within ItemDataBound, you could do something like the following:
Protected Sub rptArticleContent_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptArticleContent.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
Dim Links As String = e.Item.DataItem("Links")
Dim LinksStr As String() = Links.Split(";")
Dim Ltl As Literal = e.Item.FindControl("Ltl")
Dim Inc As Integer = 1
For Each item As String In LinksStr
Ltl.Text += String.Format("<a href='{0}'>Link {1}</a>", item, Inc)
Inc += 1
Next
End Select
End Sub
C# equivalent code:
protected void rptArticleContent_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
switch (e.Item.ItemType) {
case ListItemType.Item:
case ListItemType.AlternatingItem:
string Links = e.Item.DataItem("Links");
string[] LinksStr = Links.Split(";");
Literal Ltl = e.Item.FindControl("Ltl");
int Inc = 1;
foreach (string item in LinksStr) {
Ltl.Text += string.Format("<a href='{0}'>Link {1}</a>", item, Inc);
Inc += 1;
}
break;
}
}
这篇关于中继器绑定,具有一定的数据的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!