简体   繁体   中英

Repeater OnItemDataBound, how to get the current row's data in codebehind?

In my repeater, I want to set the content of a literal like:

<ItemTemplate>
  <asp:Literal id="lit" runat="server" />
</ItemTemplte>

I have my OnDataItemBound method in my code behind setup.

I've done this before, but only setting labels not actually getting the data for the current row that is being iterated on.

How do I get the data and the columns etc?

By using the RepeaterItemEventArgs in the OnDataItemBound method, you can access your data object through e.Item.DataItem :

void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
    var obj = (MyObject)e.Item.DataItem;
    // use your object here to populate text boxes etc...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM