Dropdownlist ASP

  • Thread starter Thread starter koumides
  • Start date Start date
K

koumides

I have the following code:

<asp:DropDownList id="Dropdownlist1" runat="server">

<asp:ListItem value="N" text=DateTime.Now.ToLongDateString() />
<asp:ListItem value="S" text="Sweden" />
<asp:ListItem value="F" text="France" />
<asp:ListItem value="I" text="Italy" />
</asp:DropDownList>

Why I don't see the date as the first value of my textbox? Instead I
see "DateTime.Now.ToLongDateString()" as first value.

Thanks
Marios Koumides
 
try this:

<asp:ListItem value="N" text='<%=DateTime.Now.ToLongDateString()%>' />
 
ok, take out the fist list item,
and in your code write

Dropdownlist1.Items.Add(DateTime.Now.ToLongDateString());
 
Is there a way to do it directly from the .aspx page? without having a
..vb file with code?
 
you don't have to use a .vb file to do code.
you can also do it within the .aspx page.

like so:

<@page language="c#" ... %>
<HTML>
<HEAD>
<SCRIPT runat=server>
void Page_Load(object Sender, EventArgs e)
{
DropdownList1.Items.Add(DateTime.Now.ToLongDateString());
}
</SCRIPT>
</HEAD>
<BODY>
<form runat=server>
<asp:DropDownList id="Dropdownlist1" runat="server">
<asp:ListItem value="S" text="Sweden" />
<asp:ListItem value="F" text="France" />
<asp:ListItem value="I" text="Italy" />
</asp:DropDownList>
</form>
</BODY>
</HTML>

Other than that, i'm not sure how to directly do it into the dropdownlist
without using code.
But there must be some way.
If your adiment about that, i suggest you start a new post to get some other
people's ideas. Specify that you do not want to use script to do it.
 
Back
Top