从数据库中检索值并绑定到下拉列表中 [英] Retrive Value from database and bind in dropdown list

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

问题描述

你好朋友

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

这是代码:-

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

推荐答案

在进行内部构造之前,请添加以下代码

Before doing anything inside if construct add this code

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

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


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

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