Hi,
I have a sql table
create table equipment(
id int not null auto_increment,
dtime timestamp not null,
door char(1) not null,
fire char(1) not null,
temperature char(1) not null
);
I want to use dropdownlist and using dtime (timestamp) to show year, month, day, time, so I can choose what data to be shown in a datagrid. All this depends from dtime field. How can I accomplish this in asp.net c#?
Thanks and regards,
Trifon.
Loading

Pradeep Mishra6 reputationPosted Jun 24, 2009, 1:55 AM EDT
private void monthsbind()
{
try
{
for (int i = 1; i <= 12; i++)
{
ListItem item = new ListItem();
item.Text = new DateTime(1900, i, 1).ToString("MMMM");
item.Value = i.ToString();
ddlMonth.Items.Add(item);
ddlMonth.SelectedValue = Convert.ToString(DateTime.Now.Month);
}
}
catch (Exception E)
{
Response.Write(E.Message.ToString());
}
}
private void yearbind()
{
try
{
for (Int32 i = Convert.ToInt32(DateTime.Now.Year) - 4; i <= Convert.ToInt32(DateTime.Now.Year) + 10; i++)
{
drpYear.Items.Add(i.ToString());
}
drpYear.Items.Insert(0, "Select Year");
drpYear.SelectedValue = Convert.ToString(DateTime.Now.Year);
}
catch (Exception E)
{
Response.Write(E.Message.ToString());
}
}
Trifon Dinev24 reputationPosted Jun 24, 2009, 3:05 AM EDT
Carmen11 reputationPosted Jun 29, 2009, 2:29 PM EDT
Datetime date = [whatever date you retrieve from database]
DropDownListTime.Text = Convert.ToString(date.Time);
DropDownListDateDay.Text = Convert.ToString(date.Day);
DropDownListDateMonth.Text = Convert.ToString(date.Month);
DropDownListDateYear.Text = Convert.ToString(date.Year);
alternatively, to grab the date values a user might select with your dropdown lost you can do:
DateTime date = Convert.ToDateTime(DropDownListDateDay.Text + " " + DropDownListDateMonth.Text + " " + DropDownListDateYear.Text + " " + DropDownListTime.Text);
JaK30 reputationPosted Jul 3, 2009, 2:47 AM EDT
I like this. I think I have the idea of how to format the data to combine the three date fields when inserting and updating using the _updating and _inserting functions.
How to I first capture the date field to use your solution:
Datetime date = [whatever date you retrieve from database]