Connecting Tech Pros Worldwide Forums | Help | Site Map

Getting values from Dropdownlist

Newbie
 
Join Date: Feb 2008
Posts: 1
#1: Feb 27 '08
I am new in .asp I am trying to use dropdownlist to display values from the database and be able to query the database based on displayed values in a dropdownlist.
the prob is when I select any value in the dropdownlist and click a button to query a database the value in the dropdownlist changes back to the first value in the dropdownlist.
Here is the code: for the dropdownlist

private void DropView_SelectedIndexChanged(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("server=ITMGR;database=CSSMoneyTR;us er id=sa;password=");
SqlDataAdapter adapP;

DataSet dsP;
SqlCommand commP=new SqlCommand("select * from RevSenderInformation where branch ='"+DropView.SelectedValue+"'",conn);
conn.Open();
adapP=new SqlDataAdapter();
dsP=new DataSet();
commP.ExecuteNonQuery();
adapP.SelectCommand=commP;
adapP.Fill(dsP,"DSender");
DataGTrans.DataSource=dsP.Tables["DSender"].DefaultView;
DataGTrans.DataBind();
conn.Close();


}
and here is the code for button

private void Button1_Click(object sender, System.EventArgs e)
{

SqlConnection conn = new SqlConnection("server=ITMGR;database=CSSMoneyTR;us er id=sa;password=");
SqlDataAdapter adapP;

DataSet dsP;
SqlCommand commP=new SqlCommand("select * from RevSenderInformation where branch ='"+DropView.SelectedValue.ToString()+"'",conn);
conn.Open();
adapP=new SqlDataAdapter();
dsP=new DataSet();
commP.ExecuteNonQuery();
adapP.SelectCommand=commP;
adapP.Fill(dsP,"DSender");
DataGTrans.DataSource=dsP.Tables["DSender"].DefaultView;
DataGTrans.DataBind();
conn.Close();
}


Please any help shall be much appreciated.I want the dropdownlist not to change values to the first one.It seems it only retains the first value.
Regards
Edward



Reply