Hi I am trying to get the values from dropdown list but everytime it selects the default
value

asp code:

<asp:TemplateField HeaderText="Customer Id" sortexpression="cust_id">
<EditItemTemplate>
<asp:DropDownList ID="ddl1" runat ="server"  OnLoad="ddl1_load" ></asp:DropDownList>                     
                            
                                 
</EditItemTemplate>
<ItemTemplate>
                                 <asp:Label ID="lblc" runat="server" CssClass="label" Text='<%#Eval("cust_id")%>'></asp:Label>
                                 
</ItemTemplate>
 <HeaderStyle BorderStyle="Inset" Font-Bold="True" Font-Underline="True" ForeColor="Teal" />
</asp:TemplateField>

code behind:

Protected Sub ddl1_load(ByVal sender As Object, ByVal e As EventArgs)
        Dim con As New SqlConnection
        con.ConnectionString = ""
        Dim da As New SqlDataAdapter("select custId from CustomerRegister", con)
        Dim dt As New DataTable()
        da.Fill(dt)
        Dim ddl As DropDownList = DirectCast(sender, DropDownList)
        ddl.DataSource = dt
        ddl.DataTextField = "custId"
        ddl.DataValueField = "custId"
        ddl.DataBind()
    End Sub

you can find asp.net gridview dropdown values using rowdatabound event

Sub productsGridView_RowDataBound(ByVal sender As Object, _
  ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        'determine the value of the any field
        Dim dropdownlist1 As Integer =  _
          Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, _
          "dropdownlist1 "))
        
    End If
End Sub

How would you do that in c# ?

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.