Inside the event handler the runtime gives a RepeaterCommandEventArgs
parameter (e). The e.Item property represents the Repeater Item where
the event occured (the footer item). When the code says
e.Item.FindControl(<controlname>), it is saying "Go to the
RepeaterItem where the event occured (the footer) and look for the
control with this name. Since the footer doesn't have that control the
call returns Nothing. Make any more sense?
I have a couple relavent articles here:
In Search of ASP.NET Controls
http://odetocode.com/Articles/116.aspx
DropDownList Controls In an ASP.Net DataGrid
(using a DataGrid, but the concepts are the same)
http://odetocode.com/Articles/231.aspx
--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 8 Nov 2004 06:13:02 -0800, "huzz"
<hu**@discussions.microsoft.com> wrote:
Scott, Thank you so much.
I moved to button inside the ItemTemplate and its working now.. :)
Can you please explain whats the reason i couldn't find the control when i
had the button inside the FooterTemplate?
Is there any tutorials which explains repeater in great details?
many thanks again
"Scott Allen" wrote:
In this case, the button is in the footer template, so I'm guessing
e.Item refers to the footer template instead of the item where the
drop down list lives. If you do not know which item the user was just
editing you might have to loop through all the items in the repeater
and get the updated DropDownList values.
--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 8 Nov 2004 03:04:01 -0800, "huzz"
<hu**@discussions.microsoft.com> wrote:
>I am trying to access a DropDownList control inside a repeater using
>ItemCommand as shown below but for some reason i can't access the
>DropDownList. When i step through the debug i get <undefine value> for the
>DropDownList
>
>What am i doing wrong?
>
><asp:Repeater ID="Repeater1" Runat="server" OnItemDataBound="create_ddl"
>OnItemCommand="Repeater1_ItemCommand">
> <HeaderTemplate>
> <table>
> <tr>
> Edit Details
> </tr>
> </HeaderTemplate>
> <ItemTemplate>
> <tr>
> <td>
> <asp:DropDownList ID="ddl" Runat="server"></asp:DropDownList>
> </td>
> </tr>
>
> <tr>
> <td>
> <asp:TextBox ID="StaffComments" Runat="server"
>TextMode="MultiLine" Text='<%# DataBinder.Eval(Container.DataItem,
>"StaffPriority")%>' Width="400" Height="40"></asp:TextBox>
> </td>
> </tr>
>
></ItemTemplate>
><FooterTemplate>
><tr>
><td colspan="2"><asp:Button runat="server" Text="Save
>Changes"></asp:Button></td>
></tr>
></table>
></FooterTemplate>
></asp:Repeater>
>
> public void Repeater1_ItemCommand(object s, RepeaterCommandEventArgs e)
> {
> DropDownList ddl1 = (DropDownList)e.Item.FindControl("ddl");
>
> if(ddl1 !=null)
> {
> Response.Write(ddl1.SelectedIndex.ToString());
> }
> else
> {
> Response.Write("ddl is null");
> }
> }