Dropdown Databinding with Hardcoded values

Last post 09-19-2008 4:36 PM by ziongates. 2 replies.

Sort Posts:

  • Dropdown Databinding with Hardcoded values

    07-23-2008, 12:54 PM
    • Member
      1 point Member
    • ziongates
    • Member since 07-23-2008, 12:41 PM
    • Posts 5

    Greetings Guys, I'm stumped here.

     I need to implement a drop down list of 3 values in the CurrentStatus Field which will appear in edit mode. I can accomplish that part (The GUI aspect) but getting the update T-SQL to use the value in the dropdown is the challenge.


    The Update code is;

     

    UPDATE [database] SET

    [Status] = @column4,
    [Customer#] = @column3

    WHERE [ID] = @original_ID


    The c# code for that button in gridview is;

                   <EditItemTemplate>
                       <asp:DropDownList ID="CurrentStatus" runat="server">
                           <asp:ListItem Selected="True">PendingApporval</asp:ListItem>
                           <asp:ListItem>Active</asp:ListItem>
                           <asp:ListItem>Inactive</asp:ListItem>
                       </asp:DropDownList>
                   </EditItemTemplate>

    I think I somehow need to pass the selected value of CurrentStatus to column4 so it can be used in the query. Note that I don't want CurrentStatus to be poulated from the current database values. I want to use only the hardcoded values in the dropdown. So the common twoway databinding fails me with the error "items not in list"

    Any Ideas?

  • Re: Dropdown Databinding with Hardcoded values

    07-27-2008, 11:23 PM
    Answer

    Hi ziongates,

    Commonly, we'll use Bind to implement a two-way binding between the control and database. I don't know why you don't need to two-way binding. If you need to a one-way binding, you can try Eval instead. So the code should be like this, for example:

     

    <EditItemTemplate>
      <asp:DropDownList ID="CurrentStatus" SelectedValue='<%# Bind("column4") %>' runat="server">
        <asp:ListItem Selected="True">PendingApporval</asp:ListItem>
        <asp:ListItem>Active</asp:ListItem>
        <asp:ListItem>Inactive</asp:ListItem>
      </asp:DropDownList>
    </EditItemTemplate>
    Thanks. 
    David Qian
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Dropdown Databinding with Hardcoded values

    09-19-2008, 4:36 PM
    • Member
      1 point Member
    • ziongates
    • Member since 07-23-2008, 12:41 PM
    • Posts 5

    I got it! Thanks for the help. That would have taken a while for me to figure out solo. I REALLY appreciate your patient words.

Page 1 of 1 (3 items)