Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0CanCan't access dropdownlist within Formview from codebehind :(
Previous
 
Next
New Post
3/26/2008 2:32 AM
 

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

 
New Post
3/26/2008 11:38 AM
 

I think your issue is that the FormView isn't always displaying the InsertItemTemplate, so especially initially, there is no DropDownList to reference.  Try moving your databinding to the .ascx, something like

<asp:DropDownList ID="ChooseLogoDropDown" runat="server" Width="100%" DataSource='<%# GetFiles() %>'/>

 Hope it helps,


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
New Post
3/26/2008 12:06 PM
 

I am not suggesting that this is the best method but it works for me:

1) Create a Insert button with the CommandName of "InsertManually"

2) Wire up a method to the "ItemCommand" of the FormView (this method will be fired any time ANY button is clicked on the Form).

3) Put code such as this in that method (here I am using Linq to SQL but you could easily use DAL+ or DAL or whatever):

 

 

 

        protected void LVCarLocations_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "InsertManually")
            {
                DropDownList ddlDivision = (DropDownList)e.Item.FindControl("ddlDivision");

                CarControlDataContext CarControlDataContext = new CarControlDataContext();

                CarDivMembership CarDivMembership = new CarDivMembership();
                CarDivMembership.DivisionID = ddlDivision.SelectedValue;

                CarControlDataContext.CarDivMemberships.InsertOnSubmit(CarDivMembership);
                CarControlDataContext.SubmitChanges();

            }
        }



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
3/26/2008 6:22 PM
 

Brian,

Thanks for that input, i modified my code by moving the codebehind in page_load to a protected object getfiles(), and used exactly the code you suggested in the aspx to execute that function as the datasource, i did have to swap out my manual datasource and databind commands in the .cs to a simple return "arraylist"; and all is working perfectly - as soon as you made that comment i realised. Being new to ASP i am not sure how certain things are handled, for instance the form in question is only visible in insert mode, a button elsewhere on the screen is available to logged in users and they can click on that to set my form.visbile = true, i clearly never stopped to think about it, but the fact its invisible on most page loads would mean it doesn't exist to bind too!

Michael,

Thank you also for your suggestion, i have used it to solve another problem as well!

On a further note, my little coding project is almost complete bar one issue, imagine this is a bookstore (its not but that will do), and there is a datalist displaying books for sale, however i have a gridview inside each datalist item which has to load (based on the current datalist item's ID) any 'single line' comments about the book from a second datasource who's selectall function is based on WHERE COMMENTID = ID. Would i be going the right way if i was to assume i am going to need to program a loop to step through each datalist item on... page load, and repopulate each gridview instance with the correct information? or is there a simpler way to do this.

Many thanks, Charles

 
New Post
3/26/2008 7:04 PM
 

Hmm, Michael this may be moreso one for you.

The basics of my little project are a modification of your samples on adef, the tradingpost tutorial to be specific.

now that i have my dropdownbox as follows

<asp:DropDownList ID="ChooseLogoDropdown" runat="server" DataSource='<%# getfiles() %>' Width="100%">

It correctly populates the list with what it is meant to however when i click to submit the form naturally it posts a Null for the field "logo"

for example my title field is a textbox <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox></td>, i can see the Bind("Title") must be what connects my form to the Title object? in the info class under the app_code folder. However being that i've modified your work, i of course dont exactly understand it, and have aboslutely no idea how to bind my dropdownlist's selected value to the 'logo' object in the filemaninfo.cs class. Any suggestions?

Many thanks, Charles

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0CanCan't access dropdownlist within Formview from codebehind :(


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out