在页面上,我有1个下拉列表,并且公司的名称已绑定在该列表中....&在下面详细阅读 [英] At a page i have 1 dropdown and the name of the companies are binded in that....& read in details below
问题描述
在页面上,我有1个下拉列表,并且分支的名称已绑定在该列表中,我希望根据从下拉列表中选择的内容在Gridview中显示分支的详细信息.....如何可能,我希望公司名称应该在下拉列表中,并且应该根据branch_id显示数据,因为公司名称可以相同.........答案plz
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
推荐答案
您需要将下拉列表绑定为类似的内容
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";
然后在selectedindex更改时使用此
then on selectedindex changed use this
query="select * from table where branchid="+dropdown.SelectedValue;
希望您了解:)
Hope you have understand :)
<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();
在下拉的selectedindexchanged事件中,编写以下
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();
}
这篇关于在页面上,我有1个下拉列表,并且公司的名称已绑定在该列表中....&在下面详细阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!