Hi
I am geeting above error on below line. In ltrlSessionDate.Text value is "21-06-2023"
DateTime sessionDate = DateTime.ParseExact(ltrlSessionDate.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
Thanks
Hi
I am geeting above error on below line. In ltrlSessionDate.Text value is "21-06-2023"
DateTime sessionDate = DateTime.ParseExact(ltrlSessionDate.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 20, 2023, 12:52 AM EDT
The error you are encountering could occur due to a few different reasons.
First, make sure that the value of
ltrlSessionDate.Textis indeed "21-06-2023" and that it is not null or empty.Secondly, ensure that the format specified in
DateTime.ParseExactmatches the format of the date string exactly. In this case, it looks like you are trying to parse a date in the format "dd-MM-yyyy". If the format of the date string is different, you will need to adjust the format string accordingly.Finally, it is possible that the culture specified in
CultureInfo.InvariantCulturemay not be appropriate for the date format you are trying to parse. You may need to specify a different culture that matches the format of the date string.To troubleshoot the issue further, you can try adding some error handling to your code to catch any exceptions that may be thrown during the parsing process. For example:
try { DateTime sessionDate = DateTime.ParseExact(ltrlSessionDate.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture); } catch (Exception ex) { // Handle the exception here }This will allow you to identify and handle any errors that may occur during the parsing process.
Thanks
Naimish Makwana
Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 20, 2023, 12:51 AM EDT
DateTime sessionDate = DateTime.ParseExact(ltrlSessionDate.Text + " 00:00 AM", "dd-MM-yyyy hh:mm tt", CultureInfo.InvariantCulture);Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 20, 2023, 1:32 AM EDT
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Get the value of ltrlSessionDate from the row Literal ltrlSessionDate = (Literal)e.Row.FindControl("ltrlSessionDate"); if (ltrlSessionDate != null) { // Convert the value of ltrlSessionDate to a DateTime object DateTime sessionDate = DateTime.ParseExact(ltrlSessionDate.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture); // Compare the sessionDate with another date DateTime otherDate = new DateTime(2023, 6, 30); // Example: June 30, 2023 if (sessionDate > otherDate) { // Do something if sessionDate is later than otherDate } else { // Do something else if sessionDate is earlier or equal to otherDate } } } }Ramco RamcoRank #462 · 5.4K reputationPosted Apr 20, 2023, 1:10 AM EDT
Hi Naimish
I have below code . How in itemdatabound i can compare this with another Date
Value in
ltrlSessionDate.Textis indeed "21-06-2023".'>Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 20, 2023, 1:28 AM EDT
To compare the value of
ltrlSessionDate.Textwith another date in theItemDataBoundevent, you can parse both dates asDateTimeobjects and then compare them using theDateTimecomparison operators.For example, if you have another date stored in a variable
otherDate, you could compare it withltrlSessionDate.Textas follows:protected void YourRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Get the Literal control for the SessionDate column Literal ltrlSessionDate = (Literal)e.Item.FindControl("ltrlSessionDate"); // Parse the value of the SessionDate column as a DateTime object DateTime sessionDate = DateTime.ParseExact(ltrlSessionDate.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture); // Compare the sessionDate with another date DateTime otherDate = DateTime.Now; if (sessionDate > otherDate) { // Do something } } }In the example above, we parse the value of
ltrlSessionDate.Textas aDateTimeobject using theDateTime.ParseExactmethod, and then compare it withotherDateusing the>operator. You can modify this comparison to use any other comparison operator as needed.Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Apr 20, 2023, 1:33 AM EDT
Hi Naimish
I have written the same code but still it is giving error. When i comment it workd fine
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { RepeaterItem rptitem = e.Item; Literal ltrlSessionDate = ((Literal)e.Item.FindControl("ltrlLastSessionDate")); BALGroupParticipant bALGroupParticipant = new BALGroupParticipant(); GroupParticipant objGrpResult = bALGroupParticipant.CheckStudentAlreadyAdded(Convert.ToInt32(ltrlStudentId.Text), Convert.ToInt32(hdfGroupId.Value)); if (objGrpResult != null) { DateTime sessionDate = DateTime.ParseExact(ltrlSessionDate.Text.Trim(), "dd-MM-yyyy", CultureInfo.InvariantCulture); }Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Apr 20, 2023, 1:40 AM EDT
Hi Naimish
How i can get hiddenfield value in itemdatabound
Thanks