开发者

ASP.NET DropDownList.SelectedItem.Value

开发者 https://www.devze.com 2022-12-25 06:02 出处:网络
I h开发者_C百科ave two items in my drop down list.When I select the second item, then click on my download button, the first item is still listed as the SelectedItem.Value.However, on the web site, th

I h开发者_C百科ave two items in my drop down list. When I select the second item, then click on my download button, the first item is still listed as the SelectedItem.Value. However, on the web site, the second item is listed in the drop down list.

string fileName = downloadRspDropDown.SelectedItem.Value; 

try { 
      FileInfo file = new FileInfo(fileName); 
      if (file.Exists) {
        //perform the transmission of the Excel file} 
      else { 
         "File does not exist"}
      }


If you're getting the wrong value in a drop down list after you hit a button make sure to first check the Page_Load event.

Your dropdownlist might be getting data bound in page_load which would supersede whatever you selected.


Try to set ViewState = Enabled for this control. If this does not help, you can add a hidden field and a javascript that will be executed while the value of dropdown is changed and put this value to the HiddenField. Then you can read this hidden field on the server side and get the value

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号