I am using One Drop Down list and bind the datas from SQL Server 2005. after that i have to select one item from Dropdown list and if i click the button(i use button also) it will redirect to another page with that drop downlist text as in a querystring.
i show my code here...
In ASPX Page:
In Load:
SqlCommand cmd = new SqlCommand("sp_get", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
cmd.Connection.Close();
getlist.DataSource = dt;
getlist.DataTextField = "t_type";
getlist.DataBind();
Button Click Event:
string text = getlist.SelectedItem.Text.ToString();
Response.Redirect("searchresults.aspx?data="+text);
But it works upto bind data from DB.. When i click the button it fire to redirected page but not getting and querystring value. Even a data could not be stored in String "Text"..
Please say the solution for this.....
Ankit NandekarPosted May 24, 2011, 3:48 AM
if(!isPosback)
{
SqlCommand cmd = new SqlCommand("sp_get", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
cmd.Connection.Close();
getlist.DataSource = dt;
getlist.DataTextField = "t_type";
getlist.DataBind();
}
write this code in Form load event and try