In Drop down list, how to convert the list into suitable data
-
I am using Access database and I have a date field which is in format of DD/MM/YYYY. In my drop down list I have enabled items like 1 day, 2 day ,3days and etc. I would like to know how to convert the drop down list selection day and update the date of dB field? E.g User select from drop down list :- 2 days Current date is 03/05/2006 So the expected return date field in dB its 03/05/2006 + 2 days. FYI, I am using VB code with ASPX using ASP 2.0 WEB MATRIX. Please advise.Thanks Jason
-
I am using Access database and I have a date field which is in format of DD/MM/YYYY. In my drop down list I have enabled items like 1 day, 2 day ,3days and etc. I would like to know how to convert the drop down list selection day and update the date of dB field? E.g User select from drop down list :- 2 days Current date is 03/05/2006 So the expected return date field in dB its 03/05/2006 + 2 days. FYI, I am using VB code with ASPX using ASP 2.0 WEB MATRIX. Please advise.Thanks Jason
Use the DateAdd fucntion newDate = DateAdd(DateInterval.Day, NumberOfDaysToAdd, currentDate) cheers Phil
-
Use the DateAdd fucntion newDate = DateAdd(DateInterval.Day, NumberOfDaysToAdd, currentDate) cheers Phil
Hi Phil, My scenario is I have a data grid with the field Date set to Date/Time format. I have created a drop down list outside and hardcode drop down list into the drop down e.g 1 day, 2 day,3day. I am not sure how I could grab the value of the selected drop down list item and update it in the Date field with its DD/MM/YYYY format. The procedure you provided me could not hint me more to solving the problem.Sorry as I m still a beginner and am using ASPX but using VB.NET code. Please advise or provide any suggestions to this.Thanks. Jason
-
Hi Phil, My scenario is I have a data grid with the field Date set to Date/Time format. I have created a drop down list outside and hardcode drop down list into the drop down e.g 1 day, 2 day,3day. I am not sure how I could grab the value of the selected drop down list item and update it in the Date field with its DD/MM/YYYY format. The procedure you provided me could not hint me more to solving the problem.Sorry as I m still a beginner and am using ASPX but using VB.NET code. Please advise or provide any suggestions to this.Thanks. Jason
Still not quite sure what you're trying to do... update every row of the field date column? cheers P
-
I am using Access database and I have a date field which is in format of DD/MM/YYYY. In my drop down list I have enabled items like 1 day, 2 day ,3days and etc. I would like to know how to convert the drop down list selection day and update the date of dB field? E.g User select from drop down list :- 2 days Current date is 03/05/2006 So the expected return date field in dB its 03/05/2006 + 2 days. FYI, I am using VB code with ASPX using ASP 2.0 WEB MATRIX. Please advise.Thanks Jason
While hard-coding the DropDownlist entries, i hope you have set both Text and Value properties. if not go to the properties window of the dropdown list and click on the columns property, which will pop up new window enabling you to enter Text and Value propeties for that ddlist. if you are binding the DD list in code behind code then follow as below
DropDownList1.Items.Insert(0,"1day"); DropDownList1.Items[0].Text="1 day"; DropDownList1.Items[0].Value="1"; DropDownList1.Items.Insert(1,"2days"); DropDownList1.Items[0].Text="2 days"; DropDownList1.Items[0].Value="2";
go on filling the DropDownList1 as shown above.string val = DropDownList1.SelectedValue.ToString();
will give the Selected value of the DropDownList1 now below code will change the value of the DataGrid1 Cell values for the entire date Column. here it si assumed that Date column is the first column. if the Column position is n then replace Cell[0] with Cell[n-1]for(int i=o;i Above Single line of code can replaced as given below `string DDval = DropDownList1.SelectedValue.ToString(); for(int i=o;i once the values have been changed in the datagrid it is up to you to update the same to the database. Cheer Ramesh.Kanjinghat`
-
While hard-coding the DropDownlist entries, i hope you have set both Text and Value properties. if not go to the properties window of the dropdown list and click on the columns property, which will pop up new window enabling you to enter Text and Value propeties for that ddlist. if you are binding the DD list in code behind code then follow as below
DropDownList1.Items.Insert(0,"1day"); DropDownList1.Items[0].Text="1 day"; DropDownList1.Items[0].Value="1"; DropDownList1.Items.Insert(1,"2days"); DropDownList1.Items[0].Text="2 days"; DropDownList1.Items[0].Value="2";
go on filling the DropDownList1 as shown above.string val = DropDownList1.SelectedValue.ToString();
will give the Selected value of the DropDownList1 now below code will change the value of the DataGrid1 Cell values for the entire date Column. here it si assumed that Date column is the first column. if the Column position is n then replace Cell[0] with Cell[n-1]for(int i=o;i Above Single line of code can replaced as given below `string DDval = DropDownList1.SelectedValue.ToString(); for(int i=o;i once the values have been changed in the datagrid it is up to you to update the same to the database. Cheer Ramesh.Kanjinghat`
in the above code the fopr loop is not printed prperly
for(int i=0;i<DataGrid1.Items.Count;i++) { DataGrid1.Item[i].Cells[0].Text = Convert.ToDateTime(DataGrid1.Item [i].Cells[0].Text.ToString().AddDays(Convert.ToDouble (DropDownList1.SelectedValue.ToString())).ToString("MM/dd/yyyy") ; }
and repeat the same for the next for loop Ramesh.Kanjinghat