Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Dropdown list problem

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2009-06-18 : 11:28:58
Back again...

I would like to display the date that is shown in the dropdown a different way it is coming out of the database. I want to maintain the value as I need it for the querystring. The date now displays 5/29/2009. How can I get it to load and show whatever date that's in the BgnDte and EndDte to show a format of m/yyyy (5/2009 in the dropdownlist)

<asp:DropDownList ID="DropDownList2" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" ToolTip="Select BgnDte" DataSourceID="SqlDataSource2" DataTextField="bgndt" DataValueField="bgndt" >

</asp:DropDownList>

   <span style="font-family: Calibri"><span style="font-size: 12pt"><strong>thru</strong> 

<asp:DropDownList ID="DropDownList3" runat="server" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" ToolTip="Select EndDte" DataSourceID="SqlDataSource3" DataTextField="enddt" DataValueField="enddt" >

</asp:DropDownList><span> </span></span></span>

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2009-07-06 : 18:45:03
JJ, I realize this is weeks later and you probably already have a solution, but just to close the loop here, the easiest way is to create a second column coming back from your SQL Query that has the format you want, and map that field to the DataTextField element.

So, for example, in your SQLDataSource2 query, you would have something like:
SELECT
bgndt,
CAST(MONTH(bgndt) as VARCHAR(2)) + '/' + CAST(YEAR(bgndt) as VARCHAR(4)) AS MyNewColumnName
FROM ...

And then put MyNewColumnName in the DataTextField like this:
<asp:DropDownList ID="DropDownList2" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" ToolTip="Select BgnDte" DataSourceID="SqlDataSource2" DataTextField="MyNewColumnName" DataValueField="bgndt" >

</asp:DropDownList>

Be sure to use the DataValueField (DropDownList2.SelectedValue) for the QueryString parameter you need.

--------------------------------------------
Brand yourself at EmeraldCityDomains.com
Go to Top of Page
   

- Advertisement -