|
 |
aspx_professional thread: Nested Controls - Problem
Message #1 by "Phil Steel" <philips@t...> on Thu, 30 Aug 2001 12:06:32
|
|
Hey Phil, I too am doing battle with nested controls. There is a lot of
power here, but uncovering it has been a bit tricky.
If I'm reading you code right, your want to create a bunch drop downs and
bind them to a data source.
I would say that your best bet is with the repeater's ItemDataBound
event. It executes when an item has been bound, so you can slide in some
code for each individual items.
It would probably go something like this (C# though, sorry).
private void documentDetails_ItemDataBound(object source,
RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item)
{
DropDown LanguageDropDown = (DropDown)e.Item.FindControl
("LanguageDropDown");
LanguageDropDown.DataSource = dvLanguages;
LanguageDropDown.DataBind();
}
}
I assume that "theValue" has some relationship to the repeater's
datasource. You can set this field as the "DataKeyField" and the retrieve
a particular value with the DataKeys collection of your repeater. I can
be more specific, but I'm a little short on time. Let me know if you need
more.
There are other options for this as well, such as using the Repeaters
Items, and Controls collection (see my problem..
http://p2p.wrox.com/view.asp?list=aspx_professional&id=96210), but I
beleive that these can not be used until after the entire repeater has
been created (on a postback for example).
B
> Hi all
>
> The trouble is accessing a control which is nested inside
> a repeater:
>
> <asp:repeater id="documentDetails">
> <itemTemplate>
> <asp:dropdown id="LanguageDropDown"></asp:dropdown>
> </itemTemplate>
> </asp:repeater>
>
> It returns this error
>
> "System.NullReferenceException: Value null was found where an instance
of
> an object was required"
>
> This is the code sitting behind:
>
> LanguageDropDown.DataSource = objDataView 'DataSource property
> LanguageDropDown.DataValueField = "ID"
> LanguageDropDown.DataTextField = "Name"
> Page.DataBind()
> LanguageDropDown.Items.FindByValue(theValue).Selected = true
>
> If I take it out side the repeater tags it will populate the dropdown
from
> a DB table but it won't select the item I want.
>
> Any ideas would be greatly appreciated.
>
> Phil
|
|
 |