locked
Trying to get dropdown to populate RRS feed

  • Question

  • User-1767698477 posted

    I'm populating a dropdown programatically like so:

     ddothexpborrower1.Items.Add("-Select-")
                        ddothexpborrower1.Items.Add(tblloanappsrow.borfirst + " " + tblloanappsrow.borlast)
                        If tblloanappsrow.cborfirst <> "" Then
                            ddothexpborrower1.Items.Add(tblloanappsrow.cborfirst + " " + tblloanappsrow.cborlast)
                        End If

    This is what is on my page. When the page loads, it loads the drop down at index index 0. How do I can the correct value selected (which is in the database) on page load?

     <td align="right">Borrower: &nbsp;
                                    <asp:DropDownList ID="ddothexpborrower1" runat="server">

                                    </asp:DropDownList>

    For Each tblloanappsrow As DataSet1.LoanappsRow In tblloanapps
                       
                        ddothexpborrower1.SelectedValue = tblloanappsrow.othliabexp1bor
                        ddothexp1.SelectedValue = tblloanappsrow.othliabexp1type
                        txtothexp1amt.Text = String.Format("{0,11:###,###.00}", (Convert.ToDecimal(tblloanappsrow.othliabexp1amt)))
                        txtothexp1mo.Text = tblloanappsrow.othliabexp1mo
                        cbothexp1omit.Checked = tblloanappsrow.othliabexp1omit
    
                        ddothexpborrower2.SelectedValue = tblloanappsrow.othliabexp2bor
                        ddothexp2.SelectedValue = tblloanappsrow.othliabexp2type
                        txtothexp2amt.Text = String.Format("{0,11:###,###.00}", (Convert.ToDecimal(tblloanappsrow.othliabexp2amt)))
                        txtothexp2mo.Text = tblloanappsrow.othliabexp2mo
                        cbothexp2omit.Checked = tblloanappsrow.othliabexp2omit
    
                        ddothexpborrower3.SelectedValue = tblloanappsrow.othliabexp3bor
                        ddothexp3.SelectedValue = tblloanappsrow.othliabexp3type
                        txtothexp3amt.Text = String.Format("{0,11:###,###.00}", (Convert.ToDecimal(tblloanappsrow.othliabexp3amt)))
                        txtothexp3mo.Text = tblloanappsrow.othliabexp3mo
                        cbothexp3omit.Checked = tblloanappsrow.othliabexp3omit
    
                        ddothexpborrower1.Items.Add("-Select-")
                        ddothexpborrower1.Items.Add(tblloanappsrow.borfirst + " " + tblloanappsrow.borlast)
                        If tblloanappsrow.cborfirst <> "" Then
                            ddothexpborrower1.Items.Add(tblloanappsrow.cborfirst + " " + tblloanappsrow.cborlast)
                        End If
                        ddothexpborrower2.Items.Add("-Select-")
                        ddothexpborrower2.Items.Add(tblloanappsrow.borfirst + " " + tblloanappsrow.borlast)
                        If tblloanappsrow.cborfirst <> "" Then
                            ddothexpborrower2.Items.Add(tblloanappsrow.cborfirst + " " + tblloanappsrow.cborlast)
                        End If
                        ddothexpborrower3.Items.Add("-Select-")
                        ddothexpborrower3.Items.Add(tblloanappsrow.borfirst + " " + tblloanappsrow.borlast)
                        If tblloanappsrow.cborfirst <> "" Then
                            ddothexpborrower3.Items.Add(tblloanappsrow.cborfirst + " " + tblloanappsrow.cborlast)
                        End If
                    Next

    Thursday, May 6, 2021 3:10 AM

Answers

  • User-1767698477 posted

    I was able to resolve this by reversing the order. First create the dropdown with items. THEN select the item in the datanase.

    ddothexpborrower1.Items.Add("-Select-")
                        ddothexpborrower1.Items.Add(tblloanappsrow.borfirst + " " + tblloanappsrow.borlast)
                        If tblloanappsrow.cborfirst <> "" Then
                            ddothexpborrower1.Items.Add(tblloanappsrow.cborfirst + " " + tblloanappsrow.cborlast)
                        End If
                        ddothexpborrower2.Items.Add("-Select-")
                        ddothexpborrower2.Items.Add(tblloanappsrow.borfirst + " " + tblloanappsrow.borlast)
                        If tblloanappsrow.cborfirst <> "" Then
                            ddothexpborrower2.Items.Add(tblloanappsrow.cborfirst + " " + tblloanappsrow.cborlast)
                        End If
                        ddothexpborrower3.Items.Add("-Select-")
                        ddothexpborrower3.Items.Add(tblloanappsrow.borfirst + " " + tblloanappsrow.borlast)
                        If tblloanappsrow.cborfirst <> "" Then
                            ddothexpborrower3.Items.Add(tblloanappsrow.cborfirst + " " + tblloanappsrow.cborlast)
                        End If

                        ddothexpborrower1.SelectedValue = tblloanappsrow.othliabexp1bor
                        ddothexp1.SelectedValue = tblloanappsrow.othliabexp1type
                        txtothexp1amt.Text = String.Format("{0,11:###,###.00}", (Convert.ToDecimal(tblloanappsrow.othliabexp1amt)))
                        txtothexp1mo.Text = tblloanappsrow.othliabexp1mo
                        cbothexp1omit.Checked = tblloanappsrow.othliabexp1omit

                        ddothexpborrower2.SelectedValue = tblloanappsrow.othliabexp2bor
                        ddothexp2.SelectedValue = tblloanappsrow.othliabexp2type
                        txtothexp2amt.Text = String.Format("{0,11:###,###.00}", (Convert.ToDecimal(tblloanappsrow.othliabexp2amt)))
                        txtothexp2mo.Text = tblloanappsrow.othliabexp2mo
                        cbothexp2omit.Checked = tblloanappsrow.othliabexp2omit

                        ddothexpborrower3.SelectedValue = tblloanappsrow.othliabexp3bor
                        ddothexp3.SelectedValue = tblloanappsrow.othliabexp3type
                        txtothexp3amt.Text = String.Format("{0,11:###,###.00}", (Convert.ToDecimal(tblloanappsrow.othliabexp3amt)))
                        txtothexp3mo.Text = tblloanappsrow.othliabexp3mo
                        cbothexp3omit.Checked = tblloanappsrow.othliabexp3omit

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 6, 2021 11:49 PM