473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 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 34500
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. Can someone confirm this, or tell me what the trick...
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 DataSource method I get the error message "Object...
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 find control in ItemDataBound event. ...
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 this in the aspx:
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 Repeater_ItemBound - including setting checked/unchecked)....
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 it's ID and text properties from the repeaters rows?...
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 labels and textboxes, the value of textboxes is...
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 datalist. In datalist ItemCreated event, I try to find...
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" runat="server" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.