Results 1 to 3 of 3

Thread: Fill a Combo Box/DropDownList

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    3

    Fill a Combo Box/DropDownList

    I am trying to fill a combo box from SQL Server 2008. Getting the Combo Box to populate isn't the problem. What I need to do is have the text field read the field value that goes with a specific id that I search by, while keeping all other fields available to chose from to change the value for that specific id and save back to the database. I know this isn't clear here is the best example I can think of:
    COMBOBOX --FieldValue------->
    --DropDownField1--> Ten
    --DropDownField2--> Twenty
    --DropDownField3--> Thirty
    --DropDownField4--> Forty

    Search by id: 301
    COMBOBOX --FieldValue----> Thirty
    --DropDownField1--> Ten
    --DropDownField2--> Twenty
    --DropDownField3--> Thirty
    --DropDownField4--> Forty

    Here is the code I am using to populate the cbo:
    Private Sub PopulateAccrualCombo()
    Dim ds As New DataSet
    Dim da As New SqlClient.SqlDataAdapter

    ds.Tables.Add("ComboTable")
    da.SelectCommand = New SqlClient.SqlCommand
    ("SELECT MethodName, MethodID " & vbCrLf & _
    "FROM" & vbCrLf & _
    "acAccountingMethod ", Me.cn)

    da.Fill(ds.Tables("ComboTable"))

    wcboAccrualMethodsFuture.DataSource = ds.Tables("ComboTable")
    wcboAccrualMethodsFuture.DataValueField = "MethodID"
    wcboAccrualMethodsFuture.DataTextField = "MethodName"


    'Configuration for Future Accrual Rate
    Me.wcboAccrualMethodsFuture.Columns.Band.GridLines = Infragistics.WebUI.UltraWebGrid.UltraGridLines.None
    Me.wcboAccrualMethodsFuture.Columns.Band.ColHeadersVisible = Infragistics.WebUI.UltraWebGrid.ShowMarginInfo.No
    Me.wcboAccrualMethodsFuture.Columns.Band.RowSelectors = Infragistics.WebUI.UltraWebGrid.RowSelectors.No
    Me.wcboAccrualMethodsFuture.Columns.FromKey("MethodName").Hidden = True


    Any ideas I seriously might have to infest in some Rogaine if I have to spend another ten minutes on this. I do know that I am missing an id to compare to but when I add the id into the sql statement the combo box only fills with the one value that it equals to without the option to chose from the several others to change.

    Thanks in advance,
    Dylan

  2. #2

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    3

    Re: Fill a Combo Box/DropDownList

    If anyone else is interested I figured it out myself. Just for anyone else who is looking my problem was actually with using the infragistics webcombo. I switched to a dropdownlist:

    Private Sub PopulateAccrualCombo()
    Dim ds As New DataSet
    Dim da As New SqlClient.SqlDataAdapter

    ds.Tables.Add("ComboTable")
    da.SelectCommand = New SqlClient.SqlCommand("SELECT MethodName, MethodID " & vbCrLf & _
    "FROM" & vbCrLf & _
    "acAccountingMethod ", Me.cn)
    da.Fill(ds.Tables("ComboTable"))

    'populating the Accrual Method for future changes
    ddlAccrualCurrent.DataSource = ds.Tables("ComboTable")
    ddlAccrualCurrent.DataValueField = "MethodID"
    ddlAccrualCurrent.DataTextField = "MethodName"

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    3

    Re: Fill a Combo Box/DropDownList

    You can also use the ValueList
    Dim vl As New Infragistics.WebUI.UltraWebGrid.ValueList
    vl.DataBind(ds, "ComboTable", "MethodName", "MethodID")

    Me.Session.Item("MethodValueList") = vl

    Me.ugrdAScheduleMaint.Columns(ColumnIndex("Accrual Method")).ValueList = vl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width