Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to pass value from listbox to textbox on button click in asp.net c#


i used two text box .when i click list box one item then pass their values textbox how?
Posted
Comments
ZurdoDev 9-Feb-15 7:50am    
Where are you stuck?
Member 10918596 9-Feb-15 7:55am    
below code not working
ZurdoDev 9-Feb-15 8:11am    
1. Please remove the comment and the solution and instead click on Improve question and post the code in the question.
2. You need to be clear about "not working." What is it doing? What doesn't work?
Member 10918596 9-Feb-15 7:55am    
protected void Getdata_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strcon);
con.Open();
cmd = new SqlCommand("sp_query", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@query_name", txt_query_name.Text);
cmd.Parameters.AddWithValue("@queries", txt_query.Text);

da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

if (ds.Tables[0].Rows.Count > 0)
{
DataRow dr = ds.Tables[0].Rows[0];
txt_query_name.Text = dr["query_name"].ToString();
txt_query.Text = dr["query"].ToString();

}
}

1 solution

SqlConnection con = new SqlConnection(strcon);
con.Open();
string str = "select * from table name where query_name='" + LstBox_query_out.SelectedItem + "'";
cmd = new SqlCommand(str, con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

if (ds.Tables[0].Rows.Count > 0)
{
DataRow dr = ds.Tables[0].Rows[0];
txt_query_name.Text = dr["query_name"].ToString();
txt_query.Text = dr["query"].ToString();

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900