Need to Bind Database value to Drop Down List in GridView

Discussion in 'ASP .Net Web Controls' started by bjkaledas, May 14, 2007.

  1. bjkaledas

    bjkaledas Guest

    Hello,

    I have the following code:

    <asp:TemplateField HeaderText="Ship Date">

    <ItemTemplate>



    <asp:DropDownList id="ddlShipDate" Runat="Server"

    SelectedValue='<%# GetShipDate(Eval("SHIPDATE")) %>'

    AppendDataBoundItems="True" Font-Size="8pt">

    <asp:ListItem Value="None">None</asp:ListItem>

    <asp:ListItem Value="PROMPT">Prompt</asp:ListItem>

    </asp:DropDownList>

    </ItemTemplate>

    </asp:TemplateField>



    Public Function GetShipDate(ByVal currentshipdate As Object) As String

    If currentshipdate Is DBNull.Value And Not currentshipdate = "PROMPT" Then

    Return "None"



    End If

    Return (currentshipdate)

    End Function



    I need to include the actual value in the drop down list that is stored in
    the ShipDate field in the database table.

    I need another listitem something like this:

    <asp:ListItem Value="Ship"><%# GetShipDate(Eval("SHIPDATE")) %></asp:ListItem>

    but this does not work.



    I need this because I have selections for the null values and those that
    read "PROMPT", but not for other random values that exist. The user would be
    able to select "None", "Prompt", or leave it at the date that was stored in
    the table.



    Thanks!
     
    bjkaledas, May 14, 2007
    #1
    1. Advertising

  2. bjkaledas

    KyleK Guest

    I prefer to bind the event in the code behind. So on PageLoad bind the
    dropdown to GetShipDate and then add Prompt and None list items to the
    dropdown.

    Hope this helps.
    --
    Kyle Kelin
    ..NET Developer
    www.dotnetmafia.com


    "bjkaledas" wrote:

    > Hello,
    >
    > I have the following code:
    >
    > <asp:TemplateField HeaderText="Ship Date">
    >
    > <ItemTemplate>
    >
    >
    >
    > <asp:DropDownList id="ddlShipDate" Runat="Server"
    >
    > SelectedValue='<%# GetShipDate(Eval("SHIPDATE")) %>'
    >
    > AppendDataBoundItems="True" Font-Size="8pt">
    >
    > <asp:ListItem Value="None">None</asp:ListItem>
    >
    > <asp:ListItem Value="PROMPT">Prompt</asp:ListItem>
    >
    > </asp:DropDownList>
    >
    > </ItemTemplate>
    >
    > </asp:TemplateField>
    >
    >
    >
    > Public Function GetShipDate(ByVal currentshipdate As Object) As String
    >
    > If currentshipdate Is DBNull.Value And Not currentshipdate = "PROMPT" Then
    >
    > Return "None"
    >
    >
    >
    > End If
    >
    > Return (currentshipdate)
    >
    > End Function
    >
    >
    >
    > I need to include the actual value in the drop down list that is stored in
    > the ShipDate field in the database table.
    >
    > I need another listitem something like this:
    >
    > <asp:ListItem Value="Ship"><%# GetShipDate(Eval("SHIPDATE")) %></asp:ListItem>
    >
    > but this does not work.
    >
    >
    >
    > I need this because I have selections for the null values and those that
    > read "PROMPT", but not for other random values that exist. The user would be
    > able to select "None", "Prompt", or leave it at the date that was stored in
    > the table.
    >
    >
    >
    > Thanks!
    >
     
    KyleK, May 17, 2007
    #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. SirPoonga
    Replies:
    2
    Views:
    782
    Ben Strackany
    Jan 7, 2005
  2. Joey Liang via DotNetMonster.com

    How to bind data from database access to drop down list control?

    Joey Liang via DotNetMonster.com, May 13, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    4,339
    Eirik Eldorsen
    May 13, 2005
  3. weiwei
    Replies:
    0
    Views:
    1,034
    weiwei
    Jan 5, 2007
  4. msimmons
    Replies:
    0
    Views:
    497
    msimmons
    Jul 16, 2009
  5. Replies:
    5
    Views:
    283
Loading...

Share This Page