i have an ajax Calender extender along with textbox in gridview, it works fine, when i select some date from calendar then it tranfers date to textbox and after clicking Update button in gridview , it sends date to database , Fine

but when i don't select any thing from calender i.e. when textbox remains empty , and when i click update button , then it sends 1900-01-01,

why ? please someone help ......

here is my code , even i treid if else conditions but else never gets executed ,


protected void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
        if (e.CommandName == "Update")
            //Label lblMsgEmail = new Label();
            GridView gvr = GridView1;
            //GridViewRow r = GridView1.Rows;
            int index = Convert.ToInt32(e.CommandArgument);
            int pk = Convert.ToInt32(GridView1.DataKeys[index].Value);
            TextBox txtb = (TextBox) (gvr.Rows[index].FindControl("txtCal"));
           // TextBox txtb1 = (TextBox)(gvr.Rows[index].FindControl("txtCal2"));
            AjaxControlToolkit.CalendarExtender txtBox = (AjaxControlToolkit.CalendarExtender)(gvr.Rows[index].FindControl("CalendarExtender1"));
            txtb.Text = txtBox.SelectedDate.ToString();
            String date = Request.Form[txtb.UniqueID];
            if(date != null || date!="")
            SqlDataSource1.UpdateCommand = "UPDATE [tblScruitnyTeam] SET [interview] = '"+ date +"', [name] = @name, [designation] = @designation, [commiteerole] = @commiteerole, [signature] = @signature, [userid] = @userid WHERE [teamid] ='"+pk+"'";
             SqlDataSource1.UpdateCommand = "UPDATE [tblScruitnyTeam] SET [interview] = '" + "Null" + "', [name] = @name, [designation] = @designation, [commiteerole] = @commiteerole, [signature] = @signature, [userid] = @userid WHERE [teamid] ='" + pk + "'";
5 Years
Discussion Span
Last Post by JorgeM

Parse the string and wrap update code in,

Datetime dt;
if(DateTime.TryParse(date,out dt))
   //code to update record


@HunainHafeez : Done, Thanks alot man ! but just for learning purpose tel me that how did it work ?

I think return value of Calendar extender will be DateTime.MinValue. if you didn't select the calendar then this statement String date = Request.Form[txtb.UniqueID]; assign invalidate date value. Using DateTime.Parse, DateTime.TryParse and DateTime.ExactTryParse - static methods of DateTime struct, you can parse the string data to DateTime object and also validate date/time value.

Edited by __avd: added more explanation

Votes + Comments
wowwwwwwwwwww ! Done, Thanks alot man ! but just for learning purpose tel me that how did it work ?

Your conditional statement is always true probably because even If you don't select a date, that is the default value, not null or "" as you would expect.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.