Iterating through Repeater.Items

Discussion in 'ASP .Net' started by Mark Fox, Nov 14, 2003.

  1. Mark Fox

    Mark Fox Guest

    Hello,

    I have a repeater and in each itemtemplate I have a
    radiobuttonlist. I am attempting to figure out how on
    postback I could iterate through the rows displayed by
    the repeater and for each row grab the selected value of
    the radio button list. When is the Repeater.Items
    collection populated? I first attempted to access the
    Repeater.Items collection from the Command event of a
    normal linkbutton on the page, but it was empty. Is it
    not populated before the Command event of a linkbutton?
    In the documentation for Repeater.Items, it accesses the
    collection in the Repeater's ItemCommand event handler.
    But when I moved the linkbutton into the FooterTemplate
    of the Repeater, the itemcommand event handler isn't
    being raised even though I wired it up in
    InitializeComponent. Why might the ItemCommand not be
    raised? If it's possible to access the Repeater.Items
    collection outside the ItemCommand event handler, where
    may I do so? Here is some of the code I'm using:

    Code Behind:

    private void InitializeComponent()
    {
    this.Load += new
    System.EventHandler(this.Page_Load);

    this.rpRegistrations.ItemDataBound += new
    RepeaterItemEventHandler(rpRegistrations_ItemDataBound);
    this.rpRegistrations.ItemCommand
    += new RepeaterCommandEventHandler
    (rpRegistrations_ItemCommand);

    }


    private void rpRegistrations_ItemCommand
    (object source, RepeaterCommandEventArgs e)
    {

    // The if statement below never gets called
    if(e.CommandName == "Update")
    {
    }
    }

    Web Form:

    <asp:Repeater
    ID="rpRegistrations" Runat="server">

    <HeaderTemplate>
    <table
    border="0" cellpadding="0" cellspacing="0" width="100%">

    <tr>

    <td class="Bold">&nbsp;</td>

    <td class="Bold">Name</td>
    </tr>
    </HeaderTemplate>

    <ItemTemplate>

    <tr>

    <td class="Normal">

    <asp:RadioButtonList ID="rblNumber"
    Runat="server" CssClass="Normal"
    RepeatDirection="Horizontal" Visible="False">

    <asp:ListItem
    Value="1">One</asp:ListItem>

    <asp:ListItem Value="2"
    Selected="True">Two<asp:ListItem>

    </asp:RadioButtonList>

    </td>

    </tr>

    </ItemTemplate>

    <FooterTemplate>

    </table>

    <asp:LinkButton ID="btnUpdate"
    CommandName="Update" Runat="server" Text="Save"
    CssClass="Command" /><br>

    </FooterTemplate>
    </asp:Repeater>
     
    Mark Fox, Nov 14, 2003
    #1
    1. Advertising

  2. Mark Fox

    Mark Fox Guest

    Hello,

    I figured this out. I had EnableViewState=False.
    My bad.


    >-----Original Message-----
    >Hello,
    >
    > I have a repeater and in each itemtemplate I have a
    >radiobuttonlist. I am attempting to figure out how on
    >postback I could iterate through the rows displayed by
    >the repeater and for each row grab the selected value of
    >the radio button list. When is the Repeater.Items
    >collection populated? I first attempted to access the
    >Repeater.Items collection from the Command event of a
    >normal linkbutton on the page, but it was empty. Is it
    >not populated before the Command event of a linkbutton?
    >In the documentation for Repeater.Items, it accesses the
    >collection in the Repeater's ItemCommand event handler.
    >But when I moved the linkbutton into the FooterTemplate
    >of the Repeater, the itemcommand event handler isn't
    >being raised even though I wired it up in
    >InitializeComponent. Why might the ItemCommand not be
    >raised? If it's possible to access the Repeater.Items
    >collection outside the ItemCommand event handler, where
    >may I do so? Here is some of the code I'm using:
    >
    >Code Behind:
    >
    > private void InitializeComponent()
    > {
    > this.Load += new
    >System.EventHandler(this.Page_Load);
    >
    > this.rpRegistrations.ItemDataBound += new
    >RepeaterItemEventHandler(rpRegistrations_ItemDataBound);
    > this.rpRegistrations.ItemCommand
    >+= new RepeaterCommandEventHandler
    >(rpRegistrations_ItemCommand);
    >
    > }
    >
    >
    > private void rpRegistrations_ItemCommand
    >(object source, RepeaterCommandEventArgs e)
    > {
    >
    >// The if statement below never gets called
    > if(e.CommandName == "Update")
    > {
    >}
    >}
    >
    >Web Form:
    >
    > <asp:Repeater
    >ID="rpRegistrations" Runat="server">
    >
    > <HeaderTemplate>
    > <table
    >border="0" cellpadding="0" cellspacing="0" width="100%">
    >
    > <tr>
    >
    > <td class="Bold"> </td>
    >
    > <td class="Bold">Name</td>
    > </tr>
    > </HeaderTemplate>
    >
    > <ItemTemplate>
    >
    > <tr>
    >
    > <td class="Normal">
    >
    > <asp:RadioButtonList ID="rblNumber"
    >Runat="server" CssClass="Normal"
    >RepeatDirection="Horizontal" Visible="False">
    >
    > <asp:ListItem
    >Value="1">One</asp:ListItem>
    >
    > <asp:ListItem Value="2"
    >Selected="True">Two<asp:ListItem>
    >
    > </asp:RadioButtonList>
    >
    > </td>
    >
    > </tr>
    >
    > </ItemTemplate>
    >
    > <FooterTemplate>
    >
    > </table>
    >
    > <asp:LinkButton ID="btnUpdate"
    >CommandName="Update" Runat="server" Text="Save"
    >CssClass="Command" /><br>
    >
    > </FooterTemplate>
    > </asp:Repeater>
    >
    >.
    >
     
    Mark Fox, Nov 14, 2003
    #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. Ron
    Replies:
    0
    Views:
    466
  2. Bryan
    Replies:
    1
    Views:
    809
    Steven Cheng[MSFT]
    Mar 1, 2006
  3. Bart Van Hemelen
    Replies:
    2
    Views:
    4,717
    Bart Van Hemelen
    Sep 4, 2006
  4. Anjan Bhowmik
    Replies:
    1
    Views:
    510
    Misbah Arefin
    Feb 14, 2008
  5. carl
    Replies:
    5
    Views:
    2,502
    James Kanze
    Nov 25, 2009
Loading...

Share This Page