472,330 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

find control inside a repeater

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");
}
}
Nov 18 '05 #1
4 34390
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");
}
}


Nov 18 '05 #2
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");
}
}


Nov 18 '05 #3
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");
> }
> }



Nov 18 '05 #4
Gos
You have the button in Footer template, not in the item template. For
the ItemCommand to work, you should have the button as part of your
Item template.

"huzz" <hu**@discussions.microsoft.com> wrote in message news:<81**********************************@microso ft.com>...
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");
}
}

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Georges Heinesch | last post by:
Hi. Is it possible to put a tab control inside another tab control. I tried it several times, but for some reason this doesn't seem to work. ...
2
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the...
3
by: P.L. | last post by:
Hi! I have problem with Datarepeater control. When I load template from external aspx file ItemTemplate = Page.LoadTemplate(....); I can't...
0
by: John Crowley | last post by:
I'm having an odd problem with viewstate and a dynamically created control inside a repeater template. Basically, I have a repeater setup like...
3
by: JD | last post by:
Hello, I have a problem with checkboxlist inside Repeater (in ASP.NET page). I am able to create Checkboxlist and bind it (inside...
5
by: Matt Jensen | last post by:
Am I right in saying that you can't have a Radiobutton web control inside a repeater bound to a database datasource and (inline) dynamically set...
1
by: jl817cn | last post by:
It's strange. The page is using master page, the repeater control is placed in contentplaceholder. In repeater Itemtemplate, there are several...
1
by: Salim | last post by:
Hi, I'm trying to get UniqueID of a linkbutton. I have 2 web user controls. And a master page. In fisrst web user control there is a...
1
by: toraan | last post by:
I define some controls inside repeater itemtemplate, the problem is with the Id that are generated automatically. <asp:Repeater ID="rptThreads"...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.