如何选择下拉列表值并将其关联数据绑定到文本框中 [英] how to select a dropdownlist value and bind its relates data into a textbox

查看:100
本文介绍了如何选择下拉列表值并将其关联数据绑定到文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void DropDownListProject_SelectedIndexChanged1(object sender, EventArgs e)
       {
           if (DropDownListProject.SelectedIndex != 0)
           {
               string strTrans = string.Empty;
               SqlCommand cmd = new SqlCommand("select TransportAgency from project where proCode='" + DropDownListProject.SelectedValue.ToString() + "'", con);
               con.Open();
               strTrans = (string)cmd.ExecuteScalar();
               con.Close();
               txtTransport.Text = strTrans;
           }
       }

推荐答案

您好,请在try中写这段代码,

抓住并调整它逐行更改,例如



Hi, Write this code in try,
Catch block and debug it line by line code change like

try { 
      if (DropDownListProject.SelectedIndex != 0)
        { 
          string strTrans = string.Empty; 
          string _Query="select TransportAgency from project where proCode='" + DropDownListProject.SelectedValue.ToString() + "'"; 
    
         // Check _Query value copy that and run in Database App 
         SqlCommand cmd = new SqlCommand(_Query, con); 
         con.Open(); 
         strTrans = (string)
         cmd.ExecuteScalar(); 
         con.Close(); 
         txtTransport.Text = strTrans;
        } 
      } 
catch(Exception ex) 

{ 
  lblMsg.ForeColor=System.Drawing.Color.Red; 
  lblMsg.Text="Error:"+ex.Message;
}


这篇关于如何选择下拉列表值并将其关联数据绑定到文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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