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
JaKPosted Jul 3, 2009, 6:47 AM
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]
CarmenPosted Jun 29, 2009, 6:29 PM
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);
Trifon DinevPosted Jun 24, 2009, 7:05 AM
Pradeep MishraPosted Jun 24, 2009, 5:55 AM
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());
}
}