Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

VB.NET

 

I have a table (tableName) that has 3 columns: Name, Number, and ID. I want to be able to bind just the ID column to a dropdown list.

 

This is what I have so far, what goes into the datasource?

 

<asp:dropDownList id="ddl_ID" datasource='<%# ??? %>' runat="server"/>

 

 

Thanks,

Bill

  • Moderators
Posted

Get rid of the 'datasource' you have within your asp tags, instead do something like this in your code-behind page...

 

   Friend Sub LoadDropDown()
       Dim dv As DataView

       With ddl_ID
           dv = 'get your dataview here
           .DataSource = dv
           .DataMember = "tableName"
           .DataValueField = "id"
           .DataTextField = "name"
           .DataBind()
       End With
   End Sub

 

To later get the user's selection...

Dim mySelectedID as integer = ddl_ID.SelectedItem.Value
dim mySelectedName as string = ddl_ID.SelectedItem.Text

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...