Textbox绑定基于列表框选择

Textbox绑定基于列表框选择

本文介绍了Re:Textbox绑定基于列表框选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


列表框SelectedIndexChanged事件我写了一些用于绑定文本框的代码,但未绑定SelectedIndexChanged事件,为什么问题是什么,请帮助我一个人

请在下面的

Hi,
List box SelectedIndexChanged event i written some code for binding of textbox but it is not binding SelectedIndexChanged event why what is the issue pls help me any one

Pls find code snippet below

protected void lstAvailableroles_SelectedIndexChanged(object sender, EventArgs e)
{
    if (lstAvailableroles.SelectedValue != null)
    {
        string role_id = lstAvailableroles.SelectedValue.ToString();
         String strConnString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
         using (SqlConnection mySqlConnection = new SqlConnection(strConnString))
         {
             try
             {
                 mySqlConnection.Open();
                 SqlCommand mySqlCommand = new SqlCommand("SELECT Role_ID,Role_Name,Description FROM roles", mySqlConnection);
                 SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(mySqlCommand);
                 DataSet myDataSet = new DataSet();
                 mySqlDataAdapter.Fill(myDataSet, "roles");
                 clsencryption.decryptDataSet(myDataSet);
                 txtDescription.Text = myDataSet.Tables[0].Rows[0]["Description"].ToString();
                 txtDescription.DataBind();

             }
             catch (Exception ex)
             {

             }
         }

    }
}

推荐答案

using (SqlConnection mySqlConnection = new SqlConnection(strConnString))
{
     try
     {
         mySqlConnection.Open();
         SqlCommand mySqlCommand = new SqlCommand("SELECT Role_ID,Role_Name,Description FROM roles", mySqlConnection);
         SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(mySqlCommand);
         DataSet myDataSet = new DataSet();
         mySqlDataAdapter.Fill(myDataSet, "roles");
         clsencryption.decryptDataSet(myDataSet);
         if(myDataSet != null){
             //Checking for null value
             if(myDataSet.Tables[0].Rows[0]["Description"] != DBNull.Value){
                txtDescription.Text = myDataSet.Tables[0].Rows[0]["Description"].ToString();
             }
         }
         //txtDescription.DataBind();
     }
     catch (Exception ex)
     {

     }
}




--Amit




--Amit


这篇关于Re:Textbox绑定基于列表框选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:09