none
using sql to generate dropdown boxes in formview RRS feed

  • General discussion

  • I am using c# and a .aspx page.

    I have a formview with five fields, two of which are town and county.  I want the county to be a dropdownlist with a list of counties populated from a sql database, this I can do.  I then want the town dropdownlist to be populated from a sql database, where the county = dropdownlist1.  I've put what I thought would be right and when I view the list, the county dropdown list is populated correctly and is fine and on auto postback but the town list isn't showing anything.  Here is the form code:

    <asp:FormView id="FormView3" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1" DefaultMode="Insert" OnItemInserted="FormView3_ItemInserted" BorderStyle="Double" BorderColor="Maroon">     <EditItemTemplate>
          ID:
          <asp:label id="IDLabel2" runat="server" Text='<%# Eval("ID") %>' />
          <br />
          title:
          <asp:textbox id="titleTextBox1" runat="server" Text='<%# Bind("title") %>' />
          <br />
          FullDetails:
          <asp:textbox id="FullDetailsTextBox1" runat="server" Text='<%# Bind("FullDetails") %>' />
          <br />
          eventdate:
          <asp:textbox id="eventdateTextBox1" runat="server" Text='<%# Bind("eventdate") %>' />
          <br />
          Town:
          <asp:textbox id="TownTextBox1" runat="server" Text='<%# Bind("Town") %>' />
          <br />
          County:
          <asp:textbox id="CountyTextBox1" runat="server" Text='<%# Bind("County") %>' />
          <br />
          <asp:linkbutton id="UpdateButton0" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
          &nbsp;<asp:linkbutton id="UpdateCancelButton0" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
         </EditItemTemplate>
         <InsertItemTemplate>
          Name of activity<br />
          EG: Roller Disco / Brownies:<br />
    &nbsp;<asp:textbox id="titleTextBox2" runat="server" Height="26px" Text='<%# Bind("title") %>' Width="176px" />
          <br />
          <br />
          Tell us all about it:<br />
          (address/times etc)
          <asp:textbox id="FullDetailsTextBox2" runat="server" Height="160px" Text='<%# Bind("FullDetails") %>' TextMode="MultiLine" />
          <br />
          <br />
          Date (DD/MM/YY):
          <asp:textbox id="eventdateTextBox2" runat="server" Text='<%# Bind("eventdate") %>' />
          <br />
          <br />
          County the activity is in:<br />
    &nbsp;<asp:dropdownlist id="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="County" DataValueField="County">
           <asp:listitem></asp:listitem>
           <asp:listitem>Avon</asp:listitem>
          </asp:dropdownlist>
          <asp:sqldatasource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:kidzonemasterConnectionString %>" SelectCommand="SELECT DISTINCT [County] FROM [Towns]">
          </asp:sqldatasource>
          <br />
          Town the activity is in:<br />
          <asp:dropdownlist id="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Town" DataValueField="Town">
          </asp:dropdownlist>
          <asp:sqldatasource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:kidzonemasterConnectionString %>" SelectCommand="SELECT [Town] FROM [Towns] WHERE ([County] = @County)">
           <SelectParameters>
            <asp:formparameter FormField="dropdownlist1" Name="County" Type="String" />
           </SelectParameters>
          </asp:sqldatasource>
          <br />
          <br />
          <asp:button id="InsertButton0" runat="server" CausesValidation="True" CommandName="Insert" Text="Add Your Activity" />
          &nbsp;
         </InsertItemTemplate>
         <ItemTemplate>
          ID:
          <asp:label id="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
          <br />
          title:
          <asp:label id="titleLabel0" runat="server" Text='<%# Bind("title") %>' />
          <br />
          FullDetails:
          <asp:label id="FullDetailsLabel0" runat="server" Text='<%# Bind("FullDetails") %>' />
          <br />
          eventdate:
          <asp:label id="eventdateLabel0" runat="server" Text='<%# Bind("eventdate") %>' />
          <br />
          Town:
          <asp:label id="TownLabel0" runat="server" Text='<%# Bind("Town") %>' />
          <br />
          County:
          <asp:label id="CountyLabel0" runat="server" Text='<%# Bind("County") %>' />
          <br />
          <asp:linkbutton id="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
          &nbsp;<asp:linkbutton id="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
          &nbsp;<asp:linkbutton id="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
         </ItemTemplate>
        </asp:FormView>

    Please can anyone spot an error and help me get this form to work?

    Thanking you in advance for any help given.

    Monday, June 10, 2013 9:09 PM

All replies

  • This is NOT an Expression Web question.

    The place for this question is in the asp.net forum, where you have been pointed to before. Very few people here use asp.net or sql databases, and they are not a function of EW any more than Flash or Silverlight are.

    You will have far, far more people able to answer your question in that forum.


    Things Liberal Arts graduates never like to hear:
    “…which means you are going first in Double Jeopardy.”

    Monday, June 10, 2013 9:26 PM
  • Thanks for your reply Bill, I have already posted the question in the asp.net forum as, as you say, I have been pointed there before, but I thought it might not hurt to post the question on here too, just incase!

    Sorry if I've offended.

    Monday, June 10, 2013 9:32 PM
  • <asp:formparameter FormField="dropdownlist1" Name="County" Type="String" />

    A "formfield" type parameter is for an HTML form field, not an asp.net control.  It has no idea what an asp.net dropdownlist's selected value is.

    If you are using a value from an asp.net dropdownlist, the parameter is a ControlParameter.

    <asp:ControlParameter ControlID="dropdownlist1" Name="Country" PropertyName="SelectedValue" />

    Note:  I am not doing anything but glancing briefly at your code and noting the first thing that jumps out at me.

    Detailed asp.net questions are best asked on the asp.net forum, http://forums.asp.net/


    • Edited by KathyW2 Tuesday, June 11, 2013 2:26 PM
    Monday, June 10, 2013 9:39 PM
  • newbie_needs_help, your entire posting history has involved posting ASP.NET questions here, and you have been told before that this is not an ASP.NET forum. In addition to the recommeneded forums.asp.net, you may also find excellent help at stackoverflow.com, where there are many users who enjoy the challenge of being first in resolving such issues.

    Instead of coming here, which is not primarily an ASP.NET forum, but focuses on EW usage, HTML, and CSS, and you know it, why don't you go to where it is demonstrably true that there are people ready and willing to help you resolve your issues with ASP.NET? Just sayin'...  ;-)

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    Tuesday, June 11, 2013 1:47 AM
  • thank you for your comments and you will be pleased to know that I am using the asp.net forum as I do take on board what people say to me on here and I am very grateful for the replies.  I feel that it is always worth asking the question is an many places as I can as I may not word my questions correctly and one person may get what I am asking where another may not. I am using expression web to build a website so I didn't think people would mind me asking questions about expression web on an expression web forum and as I have previously stated (as is more than obvious) I am not an experienced programmer and require help and I thought that this is what this forum is all about.

    As you clearly think I am in the wrong place I will close my account and not use this forum again as I would not want to waste peoples time any more than I already have so I thank everyone who has ever helped me on here and bid you goodbye.

    Tuesday, June 11, 2013 6:34 AM
  • One of my tutorials covers pretty much exactly what you are trying to do, as I understand it.


    ClarkNK, A.K.A. HomePage Doctor
    HomePageDoctor.com -- Database Tutorials
    Ownertrades.com -- Created with Expression, VWDExress, SQL Express, and ASP.NET
    Arvixe -- My favored web host

    Tuesday, June 11, 2013 12:24 PM
  • newbie_needs_help, there is no need to close your account (if that is even possible; I've never found a mechanism to do that ;-). After all,  in the future you may have questions that do concern HTML, CSS, or EW usage, the actual purpose of this forum. We even have some folks here with a passing familiarity with javascript and jQuery, both of which are now used heavily in ASP.NET applications, and are stressed by Microsoft for building Windows Phone and tablet applications.

    The point we have been trying to make is that, while EW has some limited support for ASP.NET, and even allows building some fairly sophisticated applications using only the drag and drop controls in the Toolbox, and the Tag Properties editor and each control's associated menus, once you go beyond that into areas that involve more sophisticated coding, this is not the best place to get answers. As Clark has pointed out, he has tutorials that demonstrate what you are trying to do. And there are other venues—forums.asp.net and stackoverflow are two of the best—who will welcome enthusiastically more advanced coding questions.

    You are more than welcome to come to this forum for questions which actually fall within its purview. By now, you seem to know what those questions are, and which are not.  ;-)

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    Tuesday, June 11, 2013 9:23 PM