Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Not showing values in dropdownlist
and error in button



protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string query = "SELECT [Model], [SN] FROM ['ISB VAS Nodes$']";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(query, connstring);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "Model";
DropDownList1.DataValueField = "sn";
DropDownList1.DataBind();
}

}

protected void Button1_Click(object sender, EventArgs e)
{
string searchTXt = GridView2.SelectedValue.ToString(); //in this line
string query = "SELECT [Model], [SN] FROM ['ISB VAS Nodes$']";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(query, connstring);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView2.DataSource = ds;
GridView2.DataBind();
}
}
Posted
Comments
PRAKASH9 19-Apr-13 3:14am    
this is what string searchTXt = GridView2.SelectedValue.ToString(); //in this line
codeninja-C# 19-Apr-13 4:05am    
hi,
my assumption answer
string searchTXt = DropDownList1.SelectedValue.ToString(); // Instead of GridView2 use DropDownList1
--SJ

1 solution

Make sure your connection string is correctly defined.
Check if your query returns any records.

Try debugging your source code to trace the error on button click.
 
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