0

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

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by dawsonz
0

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

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.