简体   繁体   English

如何根据ASp.Net Gridview的Selected列填充下拉列表?

[英]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.

相关问题 如何获取转换后的布尔值以在asp.net gridview的可编辑下拉列表中显示为选定值? - How to get converted boolean value to show as selected value in the editable drop down list in asp.net gridview? 如何在其他下拉列表中选择ASP .NET MVC填充下拉列表 - How to populate drop down list on other drop down list selected asp .net mvc 如何在asp.net中保存下拉列表选择的索引? - How to save the drop down list selected index in asp.net? 如何使用asp.net中的另一个下拉列表更改下拉列表选择的索引和可见性? - How to change drop down list selected index and visibility using another drop down list in asp.net? GridView Asp .Net-根据同一列中第一个下拉列表的值更改第二个下拉列表的选定值 - GridView Asp .Net-Changing the selected value of a second drop down list based on value of first drop Down in same column ASP.NET MVC - 填充下拉列表 - ASP.NET MVC - Populate a drop down list asp.net:设置为下拉列表选择的默认值 - asp.net : set default value selected for a drop down list asp.net中下拉列表的选定索引更改事件 - Selected Index change event of drop down list in asp.net 无法在asp.net的下拉列表中显示选定的值 - Not able to display selected value in drop down list in asp.net 如何使用asp.net C#在GridView中使用下拉列表 - how to use drop down list in gridview using asp.net c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM