Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何填写下拉列表_Asp.net_Vb.net - Fatal编程技术网

Asp.net 如何填写下拉列表

Asp.net 如何填写下拉列表,asp.net,vb.net,Asp.net,Vb.net,大家好,我有一个问题,关于如何将项目添加到具有某些属性的dropdownlist。我的第一个想法是: <asp:GridView ID="GV_Area" runat="server" AutoGenerateColumns="false" CssClass="table table-striped bolsa-table-gv text-center" DataKeyN

大家好,我有一个问题,关于如何将项目添加到具有某些属性的dropdownlist。我的第一个想法是:

<asp:GridView ID="GV_Area" runat="server" AutoGenerateColumns="false" CssClass="table table-striped bolsa-table-gv text-center"
                                                            DataKeyNames="Area,Oferta">
       <Columns>
             <asp:BoundField DataField="Nombre" HeaderText="Nombre" ReadOnly="true" />
                     <asp:TemplateField>
                             <ItemTemplate>
                                   <asp:DropDownList ID="ddl_Especializaciones" runat="server" CssClass="selectpicker" multiple DataSource='<%#GetDropDownData(Container)%>'></asp:DropDownList>
                             </ItemTemplate>
                     </asp:TemplateField>
       </Columns>
</asp:GridView>
元素正确地包含在dropdownlist中,但仅包含文本属性。已选择该选项,但该值不起作用。你认为我做错了什么?或者,我能用另一种方式轻松地做到吗


非常感谢您的帮助

如果您在GridView中使用DropDownList,用数据填充它们的最简单方法是使用OnRowDataBound事件


也许可以尝试为DropDownList的ddl_Specializaciones数据绑定事件连接一个处理程序。非常感谢!
    Protected Function GetDropDownData(e As System.Web.UI.WebControls.GridViewRow) As ListItem()

            Dim item As ListItem = New ListItem
            Dim arr As ArrayList = New ArrayList

            item.Selected = True
            item.Text = "Hello"
            item.Value = "Hello2"
            arr.Add(item)

            Return arr
        End Function
<asp:GridView ID="GV_Area" runat="server" OnRowDataBound="GV_Area_RowDataBound">
Protected Sub GV_Area_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

    'check if the row is a datarow
    If (e.Row.RowType = DataControlRowType.DataRow) Then

        'cast the row back to a datarowview
        Dim row As DataRowView = CType(e.Row.DataItem,DataRowView)

        'use findcontrol to locate the dropdownlist
        Dim ddl As DropDownList = CType(e.Row.FindControl("ddl_Especializaciones"),DropDownList)

        'if you need to use a datasource value for filling the dropdownlist
        Dim Nombre As Integer = Convert.ToInt32(row("Nombre"))

        'now fill the dropdownlist with values

        'from a datasource, where 'textField' and `valueField` are colums/properties of the datasource
        ddl.DataSource = Common.LoadFromDB
        ddl.DataTextField = "textField"
        ddl.DataValueField = "valueField"
        ddl.DataBind

        'or add them manually
        ddl.Items.Insert(0, New ListItem("Item A", "1", true))
        ddl.Items.Insert(1, New ListItem("item B", "1", true))

    End If

End Sub