英文:
How to show or hide a textbox in asp.net based on two dates in page load event
问题
如果日期选择器的选定值小于标签上的日期值,在页面加载时,我想显示文本框,否则隐藏它。我该如何做到这一点?
英文:
I have a webform with label,2 datepicker and a textbox.I have a date value in label.On page load if datepicker selected value is less than label value,i want to show textbox,else hide it.How can i do this?
答案1
得分: 1
首先将文本框的 visible 属性设置为 false,然后执行以下步骤。
var dateFromLabel = label.text;
var dateFromPicker = DateTime.Now;
现在,将从日期选择器中获取的字符串转换为 DateTime 格式。
DateTime dateFromLabelConverted = Convert.ToDateTime(dateFromLabel);
if (dateFromPicker < dateFromLabelConverted)
{
textbox.visible = true;
}
注意: 如果日期格式不匹配,可能不会给您正确的结果。
英文:
At first set your textbox visible properties to false and do following.
var dateFromLabel = lablel.text;
var dateFromPicker = DateTime.Now;
Now, Convert this string to DateTime format which you get from datepicker i.e.
DateTime dateFromLabelConverted = Convert.ToDateTime(dateFromLabel);
if (dateFromPicker < dateFromLabelConverted )
{
textbox.visible = true;
}
Note: if date format does not matche it may not gives you proper result.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论