Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
At a page i have 1 dropdownlist and the name of the branches are binded in that and i want that the details of the branch should be shown in the gridview according to the selection from dropdownlist.....so how it can possible and i want that the name of company should be in dropdown and data should be shown according to branch_id because company name can be same............answer plz
Posted

Hi,
you need to bind dropdown some thing like this

C#
query="select branchid,compname from table";

//execute it

Dropdown.Datasource=//give datasource

dropdown.DataTextField="compname";
dropdown.DataValueField="branchid";

then on selectedindex changed use this

query="select * from table where branchid="+dropdown.SelectedValue;


Hope you have understand :)
 
Share this answer
 
v2
Comments
pallavi ajin 8-Oct-11 2:33am    
thnx its working
pallavi ajin 8-Oct-11 2:45am    
but 1 more thing on that page its showing data.nw i want to insert that br_id,br_name into table along with others values.for the insertion of br_id i m using ddl.SelectedValue()and wht will i use for name ???may i use selectedItem()?and will i have to convert ddl.selectedvalue into integer????
XML
<asp:DropDownList id="dropdown1" runat="server" OnSelectedIndexChanged="ddlBranch_SelectedIndexChanged" >
<asp:ListItem value="0">--select--


dropdown binding should be like this

C#
ddlBranch.DataSource = datatable;//datatable that contains branch names and branch id's
           ddlBranch.DataTextField = "BRANCH_NAME";
           ddlBranch.DataValueField = "BRANCH_ID";
           ddlBranch.DataBind();


in selectedindexchanged event of dropdown write the following

C#
protected void ddlBranch_SelectedIndexChanged(object sender, EventArgs e)
    {
string query ="select * from branchtable where branchid="+ddlBranch.SelectedValue;
SqlConnection sqlConn = new SqlConnection("your connection string");
SqlDataAdapter sqlAdapter = new SqlDataAdapter(query , sqlConn);
Dataset ds=new Dataset();
sqlAdapter.Fill(ds);
gridview1.datasource=ds.Tables[0];
gridview1.databind();
}
 
Share this answer
 
v2
Comments
pallavi ajin 8-Oct-11 2:33am    
thnx
pallavi ajin 8-Oct-11 2:37am    
but 1 more thing on that page its showing data.nw i want to insert that br_id,br_name into table along with others values.for the insertion of br_id i m using ddl.SelectedValue()and wht will i use for name ???may i use selectedItem()?and will i have to convert ddl.selectedvalue into integer????
P.Salini 8-Oct-11 3:00am    
use ddl.SelectedItem.Text
pallavi ajin 8-Oct-11 3:05am    
i m using but creating probs...but leave it i hv done it by anthr way...thnx
hitech_s 8-Oct-11 3:11am    
what is the problem you are getting

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