C Sharp Textchanged事件问题 [英] C Sharp Textchanged event problem

查看:110
本文介绍了C Sharp Textchanged事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net应用程序中有一个名为 ddlWarrenty 的dropdownList,其中有一些硬编码项目,例如

''1年'

''2年''



另外两个文本框名为'' dptPurchaseDate ''和'' dptPurchaseDateEx ''

我的期望是当用户从''ddlWarrenty''中选择''1 Year''并在

''输入日期时间'dptPurchaseDate ''然后'' dptPurchaseDateEx ''将通过添加'' ddlWarrenty ''来显示日期,并且

'' dptPurchaseDate ''



我用以下方式试过这个。但它不起作用。我在 dptPurchaseDate的事件中编写了代码



In my asp.net Application there is a dropdownList named "ddlWarrenty" Where have some hard coded item such as
''1 Year''
''2 Year''
etc.
Also two textbox named ''dptPurchaseDate'' and ''dptPurchaseDateEx''
My expectation is that when user select ''1 Year'' from ''ddlWarrenty'' and input a datetime in
''dptPurchaseDate'' then ''dptPurchaseDateEx'' will be show a date by adding ''ddlWarrenty'' and
''dptPurchaseDate''

I have tried this in the following way. But it does not work. I wrote the code in the textchanged event of dptPurchaseDate

if(ddlWarrenty.SelectedItem.Text.Trim() == "1 Year")
{
      DateTime dtday = Convert.ToDateTime(dptPurchaseDate.Text.Trim());
      dptPurchaseDateEx.Text = (Convert.ToInt32(dtday) +         Convert.ToInt32(dtday.AddYears(1))).ToString();
}

推荐答案

使用DropDownList的 OnSelectedIndexChanged 事件。试试这个:

Use OnSelectedIndexChanged event of DropDownList. Try this:
protected void ddlWarrenty_SelectedIndexChanged(object sender, EventArgs e)
{
    if(ddlWarrenty.SelectedItem.Text.Trim() == "1 Year")
    {
          DateTime dtday = Convert.ToDateTime(dptPurchaseDate.Text.Trim());
          dptPurchaseDateEx.Text = (Convert.ToInt32(dtday) +         Convert.ToInt32(dtday.AddYears(1))).ToString();
    }
}





--Amit



--Amit


这篇关于C Sharp Textchanged事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆