Reputation: 116
I am using a Oracle Connection to popluate my Dropdownlist. I have created a simple dropdown ASP.NET control and Below is my code through which I am trying to populate it.
private void ShowDropDown()
{
DataTable table = new DataTable();
string connectionString = GetConnectionString();
string sqlQuery = "select distinct duty_date from duty_rota where duty_date BETWEEN SYSDATE - 300 AND SYSDATE + 300";
using (OracleConnection conn = new OracleConnection(connectionString))
{
try
{
conn.Open();
using (OracleCommand cmd = new OracleCommand(sqlQuery, conn))
{
using (OracleDataAdapter ODA = new OracleDataAdapter(cmd))
{
ODA.Fill(table);
}
}
}
catch (Exception ex)
{
Response.Write("Not Connected" + ex.ToString());
}
}
//DropDownList1.DataSource = table;
//DropDownList1.DataValueField = "";
DropDownList1.DataSource = table;
DropDownList1.DataValueField = "duty_date";
DropDownList1.DataTextFormatString = "{0:dddd,MMMM dd,yyyy}";
DropDownList1.DataBind();
}
I put the formatting in the below way
DropDownList1.DataTextFormatString = "{0:dddd,MMMM dd,yyyy}";
But the DropDownList is displaying data in 10/28/2013 format. Can somebody please help How could I Achieve the formatting of Monday, October 29, 2013 format.
Upvotes: 0
Views: 471
Reputation: 2145
When binding dropdown we need to set DataTextField and DataValueField. DataTextField is for display purpose and DataValeField is for value purpose(when want to use selected text value).
Here you forgot to add DataTextField.
DropDownList1.DataTextField = "field name";
Hope it helps you.
Thanks.
Upvotes: 1