ItemDataBound event for Repeater

Discussion in 'ASP .Net Building Controls' started by SushiSean, Jan 8, 2008.

  1. SushiSean

    SushiSean Guest

    Hello. I have Repeater and DataSource some table and I need change
    row in ItemDataBound event.

    So code looks like this
    <asp:Repeater ID="Repeater1" runat="server"
    OnItemDataBound="Repeater1_ItemDataBound">
    <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "id")%>
    </ItemTemplate>
    </asp:Repeater>

    protected void Repeater1_ItemDataBound(object sender,
    RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    DataRowView row = e.Item.DataItem as DataRowView;
    string id = row["id"].ToString(); //get value here
    ((DataRowView)e.Item.DataItem)["id"] = 5; //try to change it

    }
    }

    The problem it doesn't have effect. In repeater I see the same id.
    So the question is how to change DataItem?
     
    SushiSean, Jan 8, 2008
    #1
    1. Advertising

  2. SushiSean

    Riki Guest

    When you change the dataitem in ItemDataBound, it has already been added to
    the repeater.
    Therefore, when you change it there, it's too late already.

    Do you want to change the result in the Repeater, or do you want to change
    the data?
    In the first case, use e.Item.Text to change the contents of the item that
    has been bound:
    e.Item.Text = 5;

    --

    Riki

    "SushiSean" <> wrote in message
    news:...
    > Hello. I have Repeater and DataSource some table and I need change
    > row in ItemDataBound event.
    >
    > So code looks like this
    > <asp:Repeater ID="Repeater1" runat="server"
    > OnItemDataBound="Repeater1_ItemDataBound">
    > <ItemTemplate>
    > <%# DataBinder.Eval(Container.DataItem, "id")%>
    > </ItemTemplate>
    > </asp:Repeater>
    >
    > protected void Repeater1_ItemDataBound(object sender,
    > RepeaterItemEventArgs e)
    > {
    > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem)
    > {
    > DataRowView row = e.Item.DataItem as DataRowView;
    > string id = row["id"].ToString(); //get value here
    > ((DataRowView)e.Item.DataItem)["id"] = 5; //try to change it
    >
    > }
    > }
    >
    > The problem it doesn't have effect. In repeater I see the same id.
    > So the question is how to change DataItem?
     
    Riki, Jan 11, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. René Paschold

    Re: ItemDataBound in Repeater: FYI

    René Paschold, Oct 14, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    432
    René Paschold
    Oct 16, 2003
  2. Josh Daws
    Replies:
    2
    Views:
    22,296
    Claes
    Sep 11, 2006
  3. =?Utf-8?B?S2V2aW4gSGVjdG9y?=

    Repeater ItemCreated vs ItemDataBound

    =?Utf-8?B?S2V2aW4gSGVjdG9y?=, Apr 11, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    10,197
    Teemu Keiski
    Apr 11, 2004
  4. GaryDean
    Replies:
    1
    Views:
    8,761
    Walter Wang [MSFT]
    Aug 18, 2006
  5. NH
    Replies:
    2
    Views:
    571
    Andrew L. Van Slaars
    Dec 17, 2004
Loading...

Share This Page