GridView DropDown List RRS feed

  • Question

  • User-960441985 posted

    HOw I can access my gridview dropdown. Here is my code.

    <asp:GridView ID="dgvSearchResults" runat="server"
    EnableTheming="True" AutoGenerateColumns="false" >
    <HeaderStyle BackColor="#CCCCCC" />
    <RowStyle BackColor="White" ForeColor="Black" Font-Names="Arial,'sans serif'" />
    <asp:CommandField ShowEditButton="True">
    <ItemStyle HorizontalAlign="Center" Width="75px" ForeColor="Blue"/>

    <asp:BoundField DataField="ObjectID" HeaderText="ID" ReadOnly="true" />
    <asp:BoundField DataField="PHI_TRAINEE_NAME" HeaderText="PHI Name" ReadOnly="true" />
    <asp:BoundField DataField="DATE_SAMPLED" HeaderText="Date" ReadOnly="true"/>
    <asp:BoundField DataField="TIME_SAMPLED" HeaderText="Time" ReadOnly="true"/>
    <asp:BoundField DataField="Geometric_mean" HeaderText="GeoMetric Mean" ReadOnly="true"/>
    <asp:BoundField DataField="WATER_TEMP_C" HeaderText="Water Temp(°C)" ReadOnly="true"/>


    <asp:TemplateField HeaderText="Weather">
    <%--DataSourceID="ParkIDName_SDS" DataTextField="ParkName" DataValueField="ParkID"--%>
    <EditItemTemplate> <asp:DropDownList ID="dpGridWeather" runat="server"> </asp:DropDownList> </EditItemTemplate>
    <ItemTemplate> <asp:Label ID="lblGridWeather" runat="server" Text='<%# Bind("WEATHER") %>'></asp:Label> </ItemTemplate>

    Private Sub DpGridWeatherData()

    'Open Connection
    Dim oradb As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("OracleConnectionString").ConnectionString
    Dim OraConn As New OracleConnection(oradb)

    Dim cmd As New OracleCommand
    cmd.Connection = OraConn
    cmd.CommandText = " select id, name from table order by name asc "
    cmd.CommandType = CommandType.Text

    'Create and fill data adaptor
    Dim da As OracleDataAdapter
    da = New OracleDataAdapter(cmd)

    'Create and fill data set
    Dim dt As New DataTable

    'Release resoucrces

    'set datasoure and databind
    dpGridWeather.DataSource = dt
    dpGridWeather.DataTextField = "name"
    dpGridWeather.DataValueField = "id"


    End Sub

    Monday, August 14, 2017 9:41 PM

All replies

  • User-1508012637 posted

    Hi ramjee,

    HOw I can access my gridview dropdown.

    According to your description, please add the following code to access your dropdownlist:

    Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
    Dim dpGridWeather As DropDownList = DirectCast(e.Row.FindControl("dpGridWeather"), DropDownList) 'here you'll get the DropDownList
    End If End If End Sub
    <asp:GridView ID="dgvSearchResults" runat="server" EnableTheming="True" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
        <HeaderStyle BackColor="#CCCCCC" />

    If you have any other questions, please feel free to contact me any time.

    Best Regards

    Tuesday, August 15, 2017 4:43 AM