Click here to Skip to main content
15,885,900 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        GetCompanyDetails()
    End Sub

   
    Protected Sub GetCompanyDetails()

        Dim da As New SqlDataAdapter("SELECT [COMPCODE], [COMPNAME] FROM [TBL_COMPANY_COD]", strcon)
        Dim dt As New Data.DataTable
        da.Fill(dt)
        da.Dispose()
        ddLCmp.DataSource = dt
        ddLCmp.DataTextField = "COMPNAME"
        ddLCmp.DataValueField = "COMPCODE"
        ddLCmp.DataBind()
        'ddlcmp.ClearSelection()
    End Sub
 

End Class
Posted
Updated 8-Jun-13 2:32am
v4
Comments
Thanks7872 8-Jun-13 5:21am    
Dont post questions like this. And even you wont get any response if you post like this one. Remove all unnecessary code and post the smallest possible snippet. No one would like to go through this type of lengthy codes.
Upniwesh 8-Jun-13 6:03am    
There is not clear your problem. Can you explain?
akhil.krish 8-Jun-13 6:11am    
ex: iam select the ddl value comapany.. i wil select LG... but ddl selected value is samsung... every time select the default value samsung...
PrissySC 8-Jun-13 7:04am    
A dropdown list needs to "have" a few things in order to work with data in a grid or table.

The class is here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist.aspx

Scroll down towards the bottom and look at the examples for using with databinding.

Otherwise, you need to explain a bit more. Is the dropdown in the table or outside the table? Is it a condition by which the table is set? Is it a dropdown list for a column field value for a record? "not storing on table" is ambiguous.

1 solution

You need to bind the DropDown if Page.IsPostBack Property[^] is false. So, Page_Load should be like below.
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack
        GetCompanyDetails()
    End If
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900