我需要在包含短日期的 FormView 中的 TextBox 中找到一个值。
DateTime LastPayDate = (DateTime)FormView1.FindControl("user_last_payment_date");
我得到错误:
CS0030: Cannot convert type 'System.Web.UI.Control' to 'System.DateTime'
而且,我不知道如何以相同的格式恢复值。希望得到一些帮助,把我的头发拔掉,剩下的不多了。
谢谢
最佳答案
//If you really need to find the textbox
TextBox dateTextBox =
FormView1.FindControl("user_last_payment_date") as TextBox;
if(dateTextBox == null)
{
//could not locate text box
//throw exception?
}
DateTime date = DateTime.MinValue;
bool parseResult = DateTime.TryParse(dateTextBox.Text, out date);
if(parseResult)
{
//parse was successful, continue
}
关于c# - 从 FormView 中的 TextBox 获取日期时间值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3307593/