how to link selected value of a dropdownlist to right field?

Discussion in 'ASP .Net' started by Ben, Sep 5, 2009.

  1. Ben

    Ben Guest

    Hi,

    i defined a dropdownlist in a detailsview but the values are provided
    programmatically. This works.
    The default mod of the detailsview is INSERT.
    My problem is that the selected value of the user is not inserted in the
    table. What i don't know is how to link the selected value to the right
    field?

    With a normal field, i use something
    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("myfield")
    %>'></asp:TextBox>

    But with a dropdownlist?
    Thanks for help.
    Ben


    Here my code:

    aspx
    ----
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:myconn %>"
    InsertCommand="INSERT INTO [mytable] ([datbegin]) VALUES
    (@datbegin)">
    <InsertParameters>
    <asp:parameter Name="datbegin" Type="Integer" />
    </InsertParameters>
    </asp:SqlDataSource>

    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
    DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Insert" >
    <Fields>
    <asp:TemplateField HeaderText="datbegin">
    <InsertItemTemplate>
    <asp:DropDownList ID="begdat" runat="server" DataTextField="datbegin" >
    </asp:DropDownList>
    </InsertItemTemplate>
    </asp:TemplateField>
    </Fields>
    </asp:DetailsView>

    code-behind
    -----------

    Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles DetailsView1.DataBound
    If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
    'here the code to find the dropdownlist in the template and to
    fill it with values
    ' this works so i didn't show the code here
    '....
    end sub
     
    Ben, Sep 5, 2009
    #1
    1. Advertising

  2. Ben

    Ben Guest

    i found it:

    SelectedValue='<%# Bind("datbegin") %>'



    "Ben" <> schreef in bericht
    news:...
    > Hi,
    >
    > i defined a dropdownlist in a detailsview but the values are provided
    > programmatically. This works.
    > The default mod of the detailsview is INSERT.
    > My problem is that the selected value of the user is not inserted in the
    > table. What i don't know is how to link the selected value to the right
    > field?
    >
    > With a normal field, i use something
    > <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("myfield")
    > %>'></asp:TextBox>
    >
    > But with a dropdownlist?
    > Thanks for help.
    > Ben
    >
    >
    > Here my code:
    >
    > aspx
    > ----
    > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    > ConnectionString="<%$ ConnectionStrings:myconn %>"
    > InsertCommand="INSERT INTO [mytable] ([datbegin]) VALUES
    > (@datbegin)">
    > <InsertParameters>
    > <asp:parameter Name="datbegin" Type="Integer" />
    > </InsertParameters>
    > </asp:SqlDataSource>
    >
    > <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
    > DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Insert" >
    > <Fields>
    > <asp:TemplateField HeaderText="datbegin">
    > <InsertItemTemplate>
    > <asp:DropDownList ID="begdat" runat="server" DataTextField="datbegin"
    > >

    > </asp:DropDownList>
    > </InsertItemTemplate>
    > </asp:TemplateField>
    > </Fields>
    > </asp:DetailsView>
    >
    > code-behind
    > -----------
    >
    > Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles DetailsView1.DataBound
    > If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
    > 'here the code to find the dropdownlist in the template and to
    > fill it with values
    > ' this works so i didn't show the code here
    > '....
    > end sub
    >
    >
    >
    >
     
    Ben, Sep 5, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iain
    Replies:
    3
    Views:
    939
  2. Andy B
    Replies:
    3
    Views:
    571
    Eliyahu Goldin
    Sep 8, 2008
  3. Nathan Sokalski
    Replies:
    0
    Views:
    613
    Nathan Sokalski
    Oct 5, 2008
  4. Nathan Sokalski

    Selected ListItem in DropDownList does not appear selected

    Nathan Sokalski, Oct 5, 2008, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    293
    Nathan Sokalski
    Oct 5, 2008
  5. jr
    Replies:
    3
    Views:
    426
Loading...

Share This Page