Hi all,
I seem to be having a problem acceessing a dropdownlist from the codebehind when it is nested inside a formview's insert template.
I have poured over google and dozens of similar posts for hours and simply can't get it to NOT error. In the following code the Arraylist is built fine, and exactly as i wish for it to be built, i can successfuly use this:
testdropdown.DataSource = filelist;
testdropdown.Databind();
testdropdown is a dropdownlist placed at the end of my aspx not nested inside anything.
However if i have a formview "AddBlockForm" and i try this to access the dropdown called "ChooseLogoDropdown", i dont have a happy ending:
ddl = AddBlockForm.FindControl("ChooseLogoDropdown") as DropDownList;
ddl.DataSource = filelist;
ddl.DataBind();
it errors when at the datasource as far as i can tell. and i can't figure out a way around it no matter what i try, here is the full segment of code, followed by the formview in my aspx, any suggestions would be greatly appreciated !!
-----------------------------------
Page_load in codebehind -
ArrayList
{
filelist.Add(System.IO.
}
filelist = new ArrayList();DropDownList ddl = AddBlockForm.FindControl("ChooseLogoDropdown") as DropDownList;string[] patharray = Request.ServerVariables["PATH_INFO"].ToString().Split('/');string[] files = Directory.GetFiles(Server.MapPath(patharray[0] + "DesktopModules/Fileman/Pictures/"));foreach (string str in files)Path.GetFileName(str));try
{
ddl.DataSource = filelist;
ddl.DataBind();
}
catch
{
}
----------------------------------------------------------------
Formview and dropdown from aspx
-----------------------------------
asp:FormView ID="AddBlockForm" runat="server" DataSourceID="ObjectDataSource_Fileman"
DefaultMode="Insert" Visible="False" OnItemInserting="InsertingItem" >
<EditItemTemplate>
ModuleId:
<asp:TextBox ID="ModuleIdTextBox" runat="server" Text='<%# Bind("ModuleId") %>'>
</asp:TextBox><br />
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>'>
</asp:TextBox><br />
Title:
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>'>
</asp:TextBox><br />
Logo:
<asp:TextBox ID="LogoTextBox" runat="server" Text='<%# Bind("Logo") %>'>
</asp:TextBox><br />
Notes:
<asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
<table>
<tr>
<td>
Title:
</td>
<td>
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox></td>
</tr>
<tr>
<td style="height: 24px">
Logo:
</td>
<td style="height: 24px">
<asp:DropDownList ID="ChooseLogoDropdown" runat="server"
Width="100%">
</asp:DropDownList></td>
</tr>
<tr>
<td>
Notes:
</td>
<td>
<asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>'></asp:TextBox></td>
</tr>
</table>
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert" OnClick="blockformhide_Click1"></asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel" OnClick="blockformhide_Click1"></asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
ModuleId:
<asp:Label ID="ModuleIdLabel" runat="server" Text='<%# Bind("ModuleId") %>'></asp:Label><br />
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID") %>'></asp:Label><br />
Title:
<asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>'></asp:Label><br />
Logo:
<asp:Label ID="LogoLabel" runat="server" Text='<%# Bind("Logo") %>'></asp:Label><br />
Notes:
<asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
Text="New"></asp:LinkButton>
</
</ItemTemplate>asp:FormView>
<
DropDownList