Subhamoy
Subhamoy

Reputation: 116

DropdownList binding with is not working in ASP.NET (DateFormat is not coming up in desired way)

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

Answers (1)

Harshil Raval
Harshil Raval

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

Related Questions