下拉列表控件不反映后端 [英] drop down list control not reflecting backend

查看:90
本文介绍了下拉列表控件不反映后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从页面加载数据加载,但下拉控件不反映记录





下拉列表的组成框如下





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


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

推荐答案

如果你想要反映下拉列表中的选定值。通过SelectedIndex并通过所选值的项目索引获取它的索引



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));


这篇关于下拉列表控件不反映后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆