c# - 从 FormView 中的 TextBox 获取日期时间值

标签 c# asp.net datetime formview findcontrol

我需要在包含短日期的 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/

相关文章:

c# - 如何禁用 MenuStrip MaximizeBox

asp.net - 在 ASP.net Core 中填充下拉列表

python - 当时间序列中的下一个值较大时过滤数据

mysql - SQL 根据出生日期计算年龄时,'> 附近的语法不正确

python - 如何将 Dataframe 时间增加 5 分钟间隔?

ios - 即使应用程序被终止,如何检测应用程序的手动时间更改

c# - Unity Error building Player 因为脚本有编译器错误

c# - 当调用长于间隔长度时, react 性扩展固定异步调用之间的间隔

c# - 如何在 Azure 辅助角色中生成安全随机数?

c# - Ajax 和简单按钮事件处理程序不起作用