473,660 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ItemC ommand">
<HeaderTemplate >
<table>
<tr>
Edit Details
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td>
<asp:DropDownLi st ID="ddl" Runat="server"> </asp:DropDownLis t>
</td>
</tr>

<tr>
<td>
<asp:TextBox ID="StaffCommen ts" Runat="server"
TextMode="Multi Line" Text='<%# DataBinder.Eval (Container.Data Item,
"StaffPriority" )%>' Width="400" Height="40"></asp:TextBox>
</td>
</tr>

</ItemTemplate>
<FooterTemplate >
<tr>
<td colspan="2"><as p:Button runat="server" Text="Save
Changes"></asp:Button></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

public void Repeater1_ItemC ommand(object s, RepeaterCommand EventArgs e)
{
DropDownList ddl1 = (DropDownList)e .Item.FindContr ol("ddl");

if(ddl1 !=null)
{
Response.Write( ddl1.SelectedIn dex.ToString()) ;
}
else
{
Response.Write( "ddl is null");
}
}
Nov 18 '05 #1
4 34517
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**@discussio ns.microsoft.co m> 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:Repeate r ID="Repeater1" Runat="server" OnItemDataBound ="create_ddl "
OnItemCommand= "Repeater1_Item Command">
<HeaderTemplate >
<table>
<tr>
Edit Details
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td>
<asp:DropDownLi st ID="ddl" Runat="server"> </asp:DropDownLis t>
</td>
</tr>

<tr>
<td>
<asp:TextBox ID="StaffCommen ts" Runat="server"
TextMode="Mult iLine" Text='<%# DataBinder.Eval (Container.Data Item,
"StaffPriority ")%>' Width="400" Height="40"></asp:TextBox>
</td>
</tr>

</ItemTemplate>
<FooterTemplat e>
<tr>
<td colspan="2"><as p:Button runat="server" Text="Save
Changes"></asp:Button></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

public void Repeater1_ItemC ommand(object s, RepeaterCommand EventArgs e)
{
DropDownList ddl1 = (DropDownList)e .Item.FindContr ol("ddl");

if(ddl1 !=null)
{
Response.Write( ddl1.SelectedIn dex.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**@discussio ns.microsoft.co m> 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:Repeate r ID="Repeater1" Runat="server" OnItemDataBound ="create_ddl "
OnItemCommand= "Repeater1_Item Command">
<HeaderTemplate >
<table>
<tr>
Edit Details
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td>
<asp:DropDownLi st ID="ddl" Runat="server"> </asp:DropDownLis t>
</td>
</tr>

<tr>
<td>
<asp:TextBox ID="StaffCommen ts" Runat="server"
TextMode="Mult iLine" Text='<%# DataBinder.Eval (Container.Data Item,
"StaffPriority ")%>' Width="400" Height="40"></asp:TextBox>
</td>
</tr>

</ItemTemplate>
<FooterTemplat e>
<tr>
<td colspan="2"><as p:Button runat="server" Text="Save
Changes"></asp:Button></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

public void Repeater1_ItemC ommand(object s, RepeaterCommand EventArgs e)
{
DropDownList ddl1 = (DropDownList)e .Item.FindContr ol("ddl");

if(ddl1 !=null)
{
Response.Write( ddl1.SelectedIn dex.ToString()) ;
}
else
{
Response.Write( "ddl is null");
}
}


Nov 18 '05 #3
Inside the event handler the runtime gives a RepeaterCommand EventArgs
parameter (e). The e.Item property represents the Repeater Item where
the event occured (the footer item). When the code says
e.Item.FindCont rol(<controlnam e>), 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**@discussio ns.microsoft.co m> 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**@discussio ns.microsoft.co m> 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:Repeate r ID="Repeater1" Runat="server" OnItemDataBound ="create_ddl "
>OnItemCommand= "Repeater1_Item Command">
> <HeaderTemplate >
> <table>
> <tr>
> Edit Details
> </tr>
> </HeaderTemplate>
> <ItemTemplate >
> <tr>
> <td>
> <asp:DropDownLi st ID="ddl" Runat="server"> </asp:DropDownLis t>
> </td>
> </tr>
>
> <tr>
> <td>
> <asp:TextBox ID="StaffCommen ts" Runat="server"
>TextMode="Mult iLine" Text='<%# DataBinder.Eval (Container.Data Item,
>"StaffPriority ")%>' Width="400" Height="40"></asp:TextBox>
> </td>
> </tr>
>
></ItemTemplate>
><FooterTemplat e>
><tr>
><td colspan="2"><as p:Button runat="server" Text="Save
>Changes"></asp:Button></td>
></tr>
></table>
></FooterTemplate>
></asp:Repeater>
>
> public void Repeater1_ItemC ommand(object s, RepeaterCommand EventArgs e)
> {
> DropDownList ddl1 = (DropDownList)e .Item.FindContr ol("ddl");
>
> if(ddl1 !=null)
> {
> Response.Write( ddl1.SelectedIn dex.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**@discussio ns.microsoft.co m> wrote in message news:<81******* *************** ************@mi crosoft.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_ItemC ommand">
<HeaderTemplate >
<table>
<tr>
Edit Details
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td>
<asp:DropDownLi st ID="ddl" Runat="server"> </asp:DropDownLis t>
</td>
</tr>

<tr>
<td>
<asp:TextBox ID="StaffCommen ts" Runat="server"
TextMode="Multi Line" Text='<%# DataBinder.Eval (Container.Data Item,
"StaffPriority" )%>' Width="400" Height="40"></asp:TextBox>
</td>
</tr>

</ItemTemplate>
<FooterTemplate >
<tr>
<td colspan="2"><as p:Button runat="server" Text="Save
Changes"></asp:Button></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>

public void Repeater1_ItemC ommand(object s, RepeaterCommand EventArgs e)
{
DropDownList ddl1 = (DropDownList)e .Item.FindContr ol("ddl");

if(ddl1 !=null)
{
Response.Write( ddl1.SelectedIn dex.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
2390
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 is. Thanks. --
2
3291
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 reference not set to an instance of an object". This error message commonly occurs when a server control is incorrecly declared, so naturally I have double checked this. To test this, I moved the aspx code for the DataGrid ('myNestedDataGrid')...
3
1751
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. ((Label)e.Item.FindControl("Label1")).Text = "text";
0
2105
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
6697
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). Checkboxlist has Autopostback=true so whenever I click on checkbox, the page is submitted to the server. Here starts my problem: I am not able to capture the click event of checkbox list to find out which checkbox was clicked (which generated click...
5
5802
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? This is the impression I've got after extensive searching and trial and error, even thought I have to say I find it hard to believe? Thanks Matt
1
2390
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 from database. there is another custom control in repeater, which inherit the label control, just add one customer property MyID. In page_load I will also call another function to set the text of custom label. the function loop through all the...
1
25002
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 a linkbutton control which is in the second web user control and in another datalist.
1
4066
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" onitemcreated="rptThreads_ItemCreated"> <HeaderTemplate> <table cellpadding="0px" cellspacing="0"> </HeaderTemplate> <ItemTemplate> <tr style="height:50px">
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8754
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.