Re: Why does FindControl not work in my sample ASP .NET 3.5 ListView with DropDownList?
|
Udmonto Oorpoi |
|
5/7/2008 10:28:11 PM |
The intuitional attempt was the following: <InsertItemTemplate> <tr style=""> <td> <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' /> </td> <td> <asp:DropDownList ID="ddlContinent" runat="server"
DataSourceID="ldsContinents"
DataTextField="Name" DataValueField="Id"
SelectedValue='<%# Bind("ContinentId") %>'/> </td> <td> <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /> <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" /> </td> </tr> </InsertItemTemplate> But this results in the error "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control". The only solution I found was, not to bind the DropDownList and store the value in the ItemInserting event of the ListView: protected void lvCountries_ItemInserting(object sender, ListViewInsertEventArgs e) { // TODO: FindControl does not find the DropDownList?? // DropDownList ddlContinent = (DropDownList)this.lvCountries.FindControl("ddlContinent"); // HACK: Find the DropDownList using a search method DropDownList ddlContinent = (DropDownList)this.Find(this.lvCountries, "ddlContinent"); // Store the continent ID e.Values["ContinentId"] = (Convert.ToInt32(ddlContinent.SelectedValue)); } private Control Find(Control control, string id) { if (control.ID == id)
{ return control; }
foreach (Control child in control.Controls)
{ Control result = this.Find(child, id); if (result != null) {
return result; }
}
return null; } Any other suggestions? And: Why does FindControl not work in my sample? Post Comments |
|
Re: Why does FindControl not work in my sample ASP .NET 3.5 ListView with DropDownList?
|
Xhestom Keith |
|
5/7/2008 10:29:24 PM |
Hi: Any other suggestions? No. And: Why does FindControl not work in my sample? Please try: protected void lvCountries_ItemInserting(object sender, ListViewInsertEventArgs e)
{ DropDownList ddl = e.Item.FindControl("ddlContinent") as DropDownList; if (ddl != null) { e.Values["ContinentId"] = (Convert.ToInt32(ddl.SelectedValue)); }
}
If it still doesn't work, please inform us. Regards Post Comments |
|
Re: Why does FindControl not work in my sample ASP .NET 3.5 ListView with DropDownList?
|
Jorgia Carranza |
|
5/7/2008 10:29:51 PM |
Just stumbled across this issue. I take it this is a bug in ListView? Is a fix forthcoming from Microsoft? I'll need to do this on a routine basis - I guess for now I should just extend ListView to correct this behavior? Post Comments |
|
Re: Why does FindControl not work in my sample ASP .NET 3.5 ListView with DropDownList?
|
Jai Dev Dhabliwala |
|
5/7/2008 10:30:15 PM |
Hi, is there anything new on this issue?
I'm quite disappointed that this stuff is not working properly,
Thanks,
Post Comments |
|