使用ToString(“Format”)方法时出错

时间:2013-12-24 08:20:10

标签: c# asp.net-3.5

我有一个my_Account页面。并且对于数据检索我使用ToString(“DD / MM / yyyy”)格式,我也检查高级如果为null但是发生了一次编译时错误,如

Error   48  No overload for method 'ToString' takes '1' arguments   F:\EasyWeb\EndUser\My_Account.aspx.cs   59  55  F:\EasyWeb\

这是我的代码:

using (DataClassesDataContext db = new DataClassesDataContext())
{
    var query = from u in db.Users
                where u.Username == user_id
                select u;
                foreach (var item in query)
                {
                    Session["Username"] = user_id;
                    hidden_profile_id.Value = item.Id.ToString();
                    lbl_user_id.Text = item.Username.ToString();
                    Bind_DDL_Title();
                    ListItem item1 = drp_title.Items.FindByText(item.Title);
                    if (item1 != null)
                    {
                        item1.Selected = true;
                    }
                    txtf_name.Text = item.First_name.ToString();
                    txt_lname.Text = item.Last_name.ToString();
                    dob.Text = item.Birth_date.ToString("DD/MM/yyyy");
                    if (item.Anniversary_date != null)
                    {

//第48行没有重载方法'ToString'取'1'参数...                          txt_adate.Text = item.Anniversary_date.ToString(“DD / MM / yyyy”);

                     }
                     Bind_DDL_Status();
                     ListItem item2 = DDL_StatusList.Items.FindByValue(item.status_id.ToString());
                     if (item2 != null)
                     {
                         item2.Selected = true;
                     }
                     txt_email.Text = item.email.ToString();
                     txt_mno.Text = item.mobile_no.ToString();
                     txt_phoneno.Text = item.phone_no ?? "".ToString();
                     txt_address.Text = item.Address ?? "".ToString();
                     Bind_DDL_Countries();
                     ListItem item3 = DDL_CountryNames.Items.FindByValue(item.country_id.ToString());
                     if (item3 != null)
                     {
                         item3.Selected = true;
                     }
                     Bind_DDL_States();
                     ListItem item4 = DDL_StateNames.Items.FindByValue(item.state_id.ToString());
                     if (item4 != null)
                     {
                         item4.Selected = true;
                     }
                     txt_city.Text = item.city_name ?? "".ToString();
                     txt_zip.Text = item.pin_code ?? "".ToString();
                     CompareValidator1.ValueToCompare = item.password.ToString();
               }
 }

请帮帮我......

1 个答案:

答案 0 :(得分:1)

您只能在DateTime或Date Object中使用ToString("DD/MM/yyyy")而不能使用所有对象。

试试这个

dob.Text = Convert.ToDateTime(item.Birth_date.ToString()).ToString("yyyy-MM-dd");