[英]How to populate Drop down list depending on the Selected column of a ASp.Net Gridview?
I am fairly new I wanted to know how to populate a drop down list on select of a grid view column. 我很新,我想知道如何在选择网格视图列时填充一个下拉列表。 I have a grid view and it has a data then i have a Drop down list I want user's to be able to click on the item in the grid view and load its ID in the Drop down list.
我有一个网格视图,它有一个数据,然后有一个下拉列表,我希望用户能够在网格视图中单击该项目并将其ID加载到下拉列表中。 It will make things easier for them to work with.
这将使他们更容易合作。 Please let me know if you have any idea how to do it.
如果您有任何想法,请告诉我。 Thanks.
谢谢。
<asp:GridView ID="gvdata" runat="server"></asp:GridView>
This is the Gridview. 这是Gridview。
Dataseet ds = new dataset(); gvdata.datasource = ds; gvdata.DataBind();
This is how i populate it. 这就是我填充它的方式。
<asp:DropDownList ID="dlItemID" Width="100px" runat="server"></asp:DropDownList></td>
This is the Drop down. 这是下拉列表。
DAL DAL= new DAL(Context, "spgetItems");
DataSet ds = new DataSet();dlItemID.DataSource = ds;
DlItemID.DataTextField = "ItemID"
DlItemId.DataValueField = "ItemID"
DlItemID.DataBind();
This is how I bind the Data to it. 这就是我将数据绑定到它的方式。
It was quiet easy. 这很安静。 I don't know why no one got it but here it is.
我不知道为什么没人得到它,但是它就在这里。
<asp:GridView ID="gvdata" EnablePersistedSelection="True" DataKeyNames="ItemID"
runat="server"
HorizontalAlign="Center" AutoGenerateColumns="False" OnSelectedIndexChanged="gvdata_SelectedIndexChanged"
CellPadding="4" ForeColor="#333333" GridLines="None" >
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:Label ID="lable" BackColor="White" runat="server" Text=""></asp:Label>
and now the c# 现在是C#
protected void gvdata_SelectedIndexChanged(object sender, EventArgs e)
{
lable.Text = "";
lable.ForeColor = Color.White ;
lable.Text = gvData.SelectedRow.Cells[0].Text;
dlItemID.ClearSelection();
dlItemID.Items.FindByValue(Lable.Text).Selected = true;
}
I simply put the selected comand value in a lable and then use the findbyValue in the dropdownlist by the value of the lable and select it very simple.oh one more thing the lable forcolor is set to white because than it matches the background color of the lable and it kind of like invisible but still there,rather then any Css property hidden features. 我只是将选定的comand值放在一个标签中,然后在下拉列表中按该标签的值使用findbyValue并选择它非常简单。另外,标签forcolor设置为白色,因为它比匹配背景色标签,它有点像隐形但仍然存在,而不是任何CSS属性隐藏的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.