本文介绍了从数据库中检索值并绑定到下拉列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我已经从数据库中检索了值并显示在下拉列表中,但是它给出了类似
的错误对象引用未设置为对象的实例."

这是代码:-

Hello friend

i have retrive value from database and display in dropdown list, but its give error like
"Object reference not set to an instance of an object."

here is code :-

db.GetAddressByOrderID(Convert.ToInt32(txtorder.Text));

                if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                     DrpShippingState.Enabled = true;
                     DrpBillingState.SelectedItem.Text = ds.Tables[0].Rows[0]["BillingState"].ToString();
                     DrpShippingState.Enabled = true;
                     DrpShippingState.SelectedItem.Text = ds.Tables[0].Rows[0]["ShippingState"].ToString();
                }



我如何在下拉列表中获取州名..???

谢谢所有Advance



how can i fetch state name in drop down..???

Thank You To all in Advance

推荐答案

DrpShippingState.DataSource = ds.Tables[0];
 DrpShippingState.DataTextField = "BillingState";
 DrpShippingState.DataValueField = "BillingState";
 DrpShippingState.DataBind();

 DrpShippingState.Items.Insert(0, new ListItem("Select State"));


这篇关于从数据库中检索值并绑定到下拉列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 00:49