我如何...使用一个下拉列表值弹出2个文本框 [英] How do i...poplate 2 textbox with one dropdownlist value

查看:77
本文介绍了我如何...使用一个下拉列表值弹出2个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想填充2个文本框,描述和单位,从下拉列表中选择值为item.i的值已尝试过代码。代码是想在dropDown中设置itemName但不知道为什么值不会在文本框中显示。我有数据库中的表命名itemMaster与字段:itemName(dropdownList),description(txtbox),单位(txtbox)所有在varchar



我有什么试过:



i want to populate 2 text box , description and unit with the selection of value from dropdownlist having values of item.i have tried the code. the code is woring to set the itemName in the dropDown but dont know why values are not shown in both the textbox. i have table in data base naming itemMaster with fields : itemName(dropdownList) , description (txtbox) ,unit(txtbox) all in varchar

What I have tried:

if (!Page.IsPostBack)
            {

                SqlConnection con = new SqlConnection("Data Source=MICKEY\\SQLEXPRESS;Initial Catalog=rr;Integrated Security=True");
                SqlCommand com = new SqlCommand("select distinct itemName from itemMaster");
                // SqlDataReader sdr;
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(com.CommandText, con);
                con.Open();
                da.Fill(ds, "itemName");
                olDDLItem.DataSource = ds.Tables[0];
                olDDLItem.DataTextField = ds.Tables[0].Columns["itemName"].ColumnName;
                olDDLItem.DataValueField = ds.Tables[0].Columns["itemName"].ColumnName;
                olDDLItem.DataBind();
                //FillDropDown();
                //ddlmrp.SelectedValue = 0;

                //ddlmrp.Items.Insert(0, new ListItem("--Select--", "0"));


            }

        }

        protected void olDDLItem_SelectedIndexChanged(object sender, EventArgs e)
        {
 ListItem objItem = olDDLItem.SelectedItem;
        string selectedItemId = objItem.Text;
        SqlConnection con = new SqlConnection("Data Source=MICKEY\\SQLEXPRESS;Initial Catalog=rr;Integrated Security=True");
        SqlCommand com = new SqlCommand("select description and unit from itemMaster where item = '" + selectedItemId + "'", con);
        DataTable PriceTable = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(com);
        con.Open();
        da.Fill(PriceTable);
        con.Close();

        oltxtDescription.Text = PriceTable.Rows[0][0].ToString().Trim();
 oltxtUnit.Text = PriceTable.Rows[0][0].ToString().Trim();

推荐答案

不要在sql查询中使用和选择多列。

don't use and in sql query to select multiple columns.
 SqlCommand com = new SqlCommand("select description and unit from itemMaster where item = '" + selectedItemId + "'", con);
//Here just remove the and,
SqlCommand com = new SqlCommand("select description, unit from itemMaster where item = '" + selectedItemId + "'", con);


这篇关于我如何...使用一个下拉列表值弹出2个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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