Need to Bind Database value to Drop Down List in GridView

B

bjkaledas

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!
 
K

KyleK

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top