从捕获数据捕获表单上的日期的文本文件生成日期名称 [英] Generate the day name from the text file capturing dates on a data capture form
问题描述
每次从日期日历文本中选择日期(即 txt_Date )时,需要在表单上生成日期名称作为禁用文字
我试过这个,但有一个错误 txt_Date.Text;
Need to generate the day name as a disabled text on a form each time I select a date from the date calendar text i.e. txt_Date on a form
I tried this, but had an error txt_Date.Text;
protected void txt_Date_TextChanged(object sender, EventArgs e)
{
//String Test;
DateTime Test = txt_Date.Text;
DayOfWeek dow = Test.DayOfWeek;
txt_Day.Text = dow.ToString();
}
任何帮助请
谢谢
我尝试了什么:
我试过这个,但有错误 txt_Date.Text;
Any help please
Thanks
What I have tried:
I tried this, but had an error txt_Date.Text;
protected void txt_Date_TextChanged(object sender, EventArgs e)
{
//String Test;
DateTime Test = txt_Date.Text;
DayOfWeek dow = Test.DayOfWeek;
txt_Day.Text = dow.ToString();
}
推荐答案
由于文字
是许多控件的有效属性,特别是TextBox和Label控件 - 您可能想要使用它们 - 并且您没有告诉我们错误消息是什么,最好的猜测很多:
1)你没有任何名为txt_Date的控件。创建一个。
2)txt_Date不是Label或TextBox。找出它是什么。
3)你不能只为一个DateTime分配一个字符串值 - 除了你可以将一个方形的钉子推入一个圆孔之外,它不会起作用。您需要首先将其转换为DateTime值,最好使用验证。
SinceText
is a valid property of many controls, and specifically of the TextBox and Label controls - which are the ones you probably want to use for this - and you don't tell us what the error message is, the best guess is many fold:
1) You don't have any control called txt_Date. Create one.
2) txt_Date is not a Label or TextBox. find out what it is.
3) You can't just assign a string value to a DateTime - that doesn't work any more than you can push a square peg into a round hole. You need to convert it to a DateTime value first, preferably with validation.
DateTime test;
if (!DateTime.TryParse(txt_Date.Text, out test))
{
... report input problem to user ...
return;
}
如果你使用DateTimePicker来选择日期,那么我们就是Value属性,它已经是一个DateTime:
If you are using a DateTimePicker to select the date, then us the Value property, which is already a DateTime:
DateTime test = txt_Date.Value;
但更改该死的名称,因为这不是基于文本的控件...
But change the damn name because that isn't a text based control...
protected void cal_SelectionChanged(object sender, EventArgs e)
{
txtDate.Text = cal.SelectedDate.Date.ToShortDateString();
txtDay.Text = cal.SelectedDate.Date.DayOfWeek.ToString();
}
这篇关于从捕获数据捕获表单上的日期的文本文件生成日期名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!