how can I get the value of each cell that I want in a repeater _DataBound sub? - this is so I can change the value a little and apply the change to a literal
Let's say this is your repeater (since you didn't include any code):
<asp:Repeater ID="_r" runat="server">
<ItemTemplate>
<asp:Literal ID="_lit" Text='<%# Eval("yourItemName")%>' runat="server"></asp:Literal>
<br /><br />
</ItemTemplate>
</asp:Repeater>
and you make an ItemDataBound
event because you want to add "meow" to the end of every literal (which otherwise will just show the value of yourItemName
from the datasource):
protected void Page_Load(object sender, EventArgs e)
{
_r.DataSource = table;
_r.ItemDataBound += new RepeaterItemEventHandler(RItemDataBound);
_r.DataBind();
}
protected void RItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Literal lit = (Literal)e.Item.FindControl("_lit");
lit.Text += "meow";
}
}
Reading: Repeater.ItemDataBound Event
You can get the literal in that row but casting the event arg:
Protected Sub repeater_dataBind(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles myRepeater.ItemDataBound
If (e.Item.ItemType <> ListItemType.Item And e.Item.ItemType <> ListItemType.AlternatingItem) Then
Return
Else
Dim myLiteral As New Literal
myLiteral = CType(e.Item.FindControl("IDofLiteral"), Literal)
End If
end Sub
You can use FindControl
to get the values of a cell inside a repeater
.
protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Literal lbl = (Literal)e.Item.FindControl("ltrl");
lbl.Text = // will give you the value for each `ItemIndex`
}
}
来源:https://stackoverflow.com/questions/15688704/asp-net-repeater-get-value-of-row-item-databound