Click here to Skip to main content
12,406,528 members (55,234 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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 7-Oct-11 20:06pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,
you need to bind dropdown some thing like this

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 Smile | :)
  Permalink  
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????
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

<asp:DropDownList id="dropdown1" runat="server" OnSelectedIndexChanged="ddlBranch_SelectedIndexChanged" >
<asp:ListItem value="0">--select--

dropdown binding should be like this

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

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();
}
  Permalink  
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????
CodeHelper_PS 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_ssc 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160730.1 | Last Updated 8 Oct 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100