locked
Insert from dropdownlist‏ RRS feed

  • Question

  • User-2118645505 posted

    Hi all,

    I am using visual studio 2010, sql 2008, .net4.

    hopefully someone can guide me in the right direction, a nice how to guide would be fantastic.

    I currently have two tables, project and projectresource.

    projectresource = resourceid, name, tel and email.
    project = projectid, projectname, customername, resourceid.

    from a "new project" webpage new projects using a form view, what I have so far is the ability to retrieve the list of resources from a dropdownlist from the project resource table, this dropdownlist shows the resource name (allowing managers to assign projects to certain people) - What i want to happen is that the resourceid is grabbed from the selected resource and inserted into the project table (resourceid) along with the other inputs as above.

    does anyone have a link to a guide to achieve this?

    Tuesday, January 3, 2012 10:11 AM

Answers

  • User2053451246 posted

    DataTextField and DataValueField come from the SQLDataSource you are getting the dropdown list items from.  Use SelectedValue='<%#Bind("FieldName")%>' to bind the selected value to the field in the SQLDataSource that feeds your FormView.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 3, 2012 4:12 PM

All replies

  • User-2010311731 posted

    The latest data access methods can be found in the following set of tutorials...

    http://www.asp.net/web-forms/tutorials

     

    Matt

    Tuesday, January 3, 2012 10:59 AM
  • User-2118645505 posted

    Thanks Matt, but I'm still a bit lost with that.

    I have managed to use dropdown list in the "new-project" webpage (which will input the details into the project table) to retrieve the list of resources from the projectresource table using the following..

    <asp:DropDownList ID="DropDownListProjectResource" runat="server" 
     DataSourceID="SqlDataSourcehld" DataTextField="name" 
    DataValueField="name" AppendDataBoundItems="True">
    <asp:ListItem Value=" "></asp:ListItem>
    </asp:DropDownList>

    But what i need to achieve now is that who ever is select from that dropdown by the manager is then inserted into the project table using their uniqueID (resourceid)

    If you could point me to the relevant part of that tutorial i would be very appreciative.

    Tuesday, January 3, 2012 11:11 AM
  • User2053451246 posted

    You have "name" for the DataTextField and DataValueField properties.  DataTextField is what displays to the user.  DataValueField is what gets stored in your database.  Change DataValueField to the uniqueID (resourceid?).

    Tuesday, January 3, 2012 2:06 PM
  • User-2118645505 posted

    Hi,

    Thanks for responding.

    Out of interest, how would that work across SQLDatasources? - I have a formview which has a SQLDataSource to the Project Table and within that the above SQLDatasource for the Dropdownlists.

    So basically, the dropdownlists pull datafrom the resourcetable via a seperate datasource, from this i need to translate the name to the resourceID and insert that into the same row within the project table.

    Tuesday, January 3, 2012 3:50 PM
  • User2053451246 posted

    DataTextField and DataValueField come from the SQLDataSource you are getting the dropdown list items from.  Use SelectedValue='<%#Bind("FieldName")%>' to bind the selected value to the field in the SQLDataSource that feeds your FormView.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 3, 2012 4:12 PM
  • User-2118645505 posted

    I'm having a blonde moment sorry.

    I had a look at this page: http://msdn.microsoft.com/en-us/library/ms178366.aspx

    But im still a tad confused.

    Does the selectedvalue still pick up the SQLDataSource from the main formview? - Ignoring the SQLDatasource of the dropdownlist?

    Tuesday, January 3, 2012 4:53 PM
  • User-2118645505 posted

    I'm having a moment sorry.

    I had a look at this page: http://msdn.microsoft.com/en-us/library/ms178366.aspx

    But im still a tad confused.

    Does the selectedvalue still pick up the SQLDataSource from the main formview? - Ignoring the SQLDatasource of the dropdownlist?

    I'm presuming the code for the dropdowns would now look like.

    <asp:DropDownList 
    ID="DropDownListProjectResource"
    runat="server" 
    DataSourceID="SqlDataSourcehld" 
    DataTextField="name" 
    DataValueField="name" 
    SelectedValue='<%#Bind("FieldName")%>'
    AppendDataBoundItems="True">
    <asp:ListItem Value=" "> </asp:ListItem> </asp:DropDownList>
    Wednesday, January 4, 2012 3:34 AM
  • User-2118645505 posted

    I'm having a moment sorry.

    I had a look at this page: http://msdn.microsoft.com/en-us/library/ms178366.aspx

    But im still a tad confused.

    Does the selectedvalue still pick up the SQLDataSource from the main formview? - Ignoring the SQLDatasource of the dropdownlist?

    I'm presuming the code for the dropdowns would now look like.

    <asp:DropDownList 
    ID="DropDownListProjectResource"
    runat="server" 
    DataSourceID="SqlDataSourcehld" 
    DataTextField="name" 
    DataValueField="name" 
    SelectedValue='<%#Bind("FieldName")%>'
    AppendDataBoundItems="True">
    <asp:ListItem Value=" ">
    </asp:ListItem>
    </asp:DropDownList>

    Wednesday, January 4, 2012 3:41 AM
  • User-2118645505 posted

    Fantastic, i got it working now!

    Wednesday, January 4, 2012 4:28 AM