Answered by:
Bind Checkboxlist with next 7 days Date Value using JQuery

Question
-
User-1241097802 posted
I have one
CheckboxList
in my page and I want to bind next 7 days (not today) value in my list dynamically. The value should me inserted in the format as shown in image below right side and when I display the page inaspx
I want to display Date and Day as shown in the 1st image format.<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>
Wednesday, February 5, 2020 10:47 AM
Answers
-
User475983607 posted
Use a custom date format string. I think you'll be interested in reading the date format docs as they cover how to format dates in detail.
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings
The best I can do for you are this point is provide the format string to use. You did not share the actual code that populates the CheckBoxList so you'll need to add the format string yourself. You should be able to figure that out on your own though.
static void Main(string[] args) { DateTime now = DateTime.Now; Console.WriteLine(now.ToString("dddd yyyy-MM-dd")); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, February 5, 2020 2:50 PM -
User665608656 posted
Hi Programming ,
As @megard said, you can convert datetime data to the format you want to display by using ToString("dddd yyyy-MM-dd") .
Below I created a case based on your needs, you can refer to it:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DateTime today = DateTime.Now; List<string> dateTimes = new List<string>(); for (int i = 1; i <= 7; i++) { dateTimes.Add(today.AddDays(i).ToString("dddd yyyy-MM-dd")); } CheckBoxList1.DataSource = dateTimes; CheckBoxList1.DataBind(); } }
Here is the result :
Best Regards,
YongQing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 6, 2020 5:52 AM
All replies
-
User475983607 posted
Use a custom date format string. I think you'll be interested in reading the date format docs as they cover how to format dates in detail.
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings
The best I can do for you are this point is provide the format string to use. You did not share the actual code that populates the CheckBoxList so you'll need to add the format string yourself. You should be able to figure that out on your own though.
static void Main(string[] args) { DateTime now = DateTime.Now; Console.WriteLine(now.ToString("dddd yyyy-MM-dd")); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, February 5, 2020 2:50 PM -
User665608656 posted
Hi Programming ,
As @megard said, you can convert datetime data to the format you want to display by using ToString("dddd yyyy-MM-dd") .
Below I created a case based on your needs, you can refer to it:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DateTime today = DateTime.Now; List<string> dateTimes = new List<string>(); for (int i = 1; i <= 7; i++) { dateTimes.Add(today.AddDays(i).ToString("dddd yyyy-MM-dd")); } CheckBoxList1.DataSource = dateTimes; CheckBoxList1.DataBind(); } }
Here is the result :
Best Regards,
YongQing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 6, 2020 5:52 AM