Insert Part:
while Inserting the date: Date: 28/02/2018 Displaying in Listview after insert 2/28/2018
Source code:
<asp:TextBox ID="txtlogdate" runat="server" Height="25px" Width="196px" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="log" ControlToValidate="txtlogdate" runat="server" ErrorMessage="*date" ForeColor="red"></asp:RequiredFieldValidator>
<cc1:CalendarExtender ID="CalendarExtender1" TargetControlID="txtlogdate" Format="dd/MM/yyyy" runat="server">
</cc1:CalendarExtender>
Code behind:
string schDate = txtlogdate.Text.Trim();
DateTime date = new DateTime();
date = DateTime.ParseExact(schDate, "dd/MM/yyyy", null);
string DateString = date.ToString("yyyy/MM/dd");
command1.Parameters.AddWithValue("?date", DateString);
Update Part: While updating the date: Dispalyed date from insert: 2/28/2018
source code:
<asp:TextBox ID="txtdate" runat="server" Text='<%# Eval("date", "{0:dd-MM-yyyy}")%>'
Height="25px" Width="196px" ></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" TargetControlID="txtdate" Format="dd/MM/yyyy" runat="server">
</cc1:CalendarExtender> </td>
code behind:
TextBox txtdate= (TextBox)lstvwInquiryLogDetails.Items[e.ItemIndex].FindControl("txtdate");
string schDatee = txtdate.Text.Trim();
DateTime date = new DateTime();
date = DateTime.ParseExact(schDatee, "dd/MM/yyyy", null);
// date = DateTime.ParseExact(schDatee, "MM/dd/yyyy", null);
string DateString = date.ToString("yyyy/MM/dd");
command.Parameters.AddWithValue("?date", DateString);
i am getting the issue while updating the date.if the date is 2/28/2018(listview)(not edited the date), it is not getting updated the details. if the date is 28/02/2018(listview)(edited the date from 2/28/2018 to 28/02/2018),it is updating the details of the row. Its like if i am changing the date of the row during update,the details are getting updated.
i used try and catch.so in the exception,it says "string is not recognised as valid datetime"