Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void gvImages_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\site\SamsungClassifieds\App_Data\Dorknozzle.mdf;Integrated Security=True;User Instance=True");
        con.Open();
        AjaxControlToolkit.CalendarExtender date = (AjaxControlToolkit.CalendarExtender)gvImages.Rows[e.RowIndex].FindControl("date3");
        //int userid = Convert.ToInt32(gvImages.DataKeys[e.RowIndex].Values["lbladid"].ToString());
        Label lbladid = (Label)gvImages.Rows[e.RowIndex].FindControl("lbladid");
        TextBox txttitl = (TextBox)gvImages.Rows[e.RowIndex].FindControl("txttitle");
        TextBox txtdesc = (TextBox)gvImages.Rows[e.RowIndex].FindControl("txtdesc");
        Label lblprice = (Label)gvImages.Rows[e.RowIndex].FindControl("lblprice");
        TextBox txtprice = (TextBox)gvImages.Rows[e.RowIndex].FindControl("txtprice");
        TextBox txtdate = (TextBox)gvImages.Rows[e.RowIndex].FindControl("txtdate");
        
   
        
        SqlCommand cmd = new SqlCommand("UPDATE AD_DETAIL SET AD_TITLE ='" + txttitl.Text + "',AD_DESC ='" + txtdesc.Text + "',AD_PRICE ='" + txtprice.Text + "',DATE =' "+ date.SelectedDate.ToString() +" 'WHERE AD_ID = '" + lbladid.Text + "'", con);
        
        //SqlCommand cmd = new SqlCommand("Update AD_DETAIL set AD_TITLE=" + txttitle.Text + "where AD_ID =" + lbladid, con);
        cmd.ExecuteNonQuery();
        gvImages.EditIndex = -1;
        Binddata();
        con.Close();

    }
Posted
Updated 8-Aug-13 8:25am
v5
Comments
So, what is the problem?
Harshit Wadhera 8-Aug-13 14:21pm    
the problem is date is stored but it is always 01/01/1900. date is not change according to user selected date.

1 solution

If you're using the ASP.Net AJAX Control Toolkit CalendarExtender, you get to get the client side value...
C#
C#
string date= Request.Form[txtDate.UniqueID];

VB.net
VB
Dim strDate As String = Request.Form(txtDate.UniqueID)
 
Share this answer
 
v2
Comments
Harshit Wadhera 9-Aug-13 4:06am    
your ans is right but i have to save dd/MM/yyyy like this but it is showing like mm/dd/yyyy this
[no name] 9-Aug-13 5:02am    
Use like string date= Request.Form[txtDate.UniqueID].ToString("dd/MM/yyyy"); Then the date will be in proper format that you required.
Harshit Wadhera 9-Aug-13 6:34am    
the code display an error of " The best overloaded method match for 'string.ToString(System.IFormatProvider)' has some invalid arguments"
[no name] 9-Aug-13 6:42am    
Use string.Format("dd/MM/yyyy",date);
Harshit Wadhera 9-Aug-13 6:52am    
Thanx dude it works.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900