Click here to Skip to main content
15,919,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Loading data from page Load , however the drop down control does not reflect the record


The composition of the drop down list box is as follows


XML
ddl_Loan_Type.SelectedValue = ds.Tables["Loans"].Rows[0]
["LOANTYPE"].ToString();</pre>







  protected void Page_Load(object sender, EventArgs e)
        {
            ///Load Begin
            if (!IsPostBack)
            {
                try
                {
                    SqlConnection connect = new SqlConnection();
                    connect.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
                    connect.Open();
                    SqlDataAdapter da = new SqlDataAdapter("select * from Loans order by idno", connect);

                    DataSet ds = new DataSet();
                    da.Fill(ds, "Loans");

                    txt_Id_Code.Text = ds.Tables["Loans"].Rows[0]["ID_CODE"].ToString();
                    txt_Appraisal_No.Text= ds.Tables["Loans"].Rows[0]["APPRS_NO"].ToString();
                    txt_Interest_Name.Text = ds.Tables["Loans"].Rows[0]["INT_NAME"].ToString();
                    ddl_Loan_Type.SelectedValue = ds.Tables["Loans"].Rows[0]
["LOANTYPE"]"ToString();




Please assist to correct this problem
Posted

1 solution

If you want to reflect the selected value in dropdownlist. Make it through SelectedIndex and get it's index through your item index of selected value

string val= ds.Tables["Loans"].Rows[0]["LOANTYPE"].ToString();

        ddl_Loan_Type.SelectedIndex = ddl_Loan_Type.Items.IndexOf(ddl_Loan_Type.Items.FindByValue(val));
 
Share this answer
 
v2
Comments
Member 10744248 29-Jun-14 9:04am    
How do you code or what will be in the SelectedIndex.

please assist

New to c#

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