显示一个DropDownList DB值 [英] Display DB values in a dropdownlist

查看:102
本文介绍了显示一个DropDownList DB值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从数据库中显示的值到一个DropDownList。但我无法得到相应的值到DDL。

 如果(dt.Rows.Count大于0)
            {
                DataTable的DT1 =新的DataTable();
                DT1 = bll.getnewid(TextBox1.Text);                    如果(dt1.Rows.Count大于0)
                    {                        会话[PID] = dt1.Rows [0] [NewidColumn]的ToString()。
                        会话[电子邮件] = dt1.Rows [0] [EMAILID]的ToString()。
                        会话[性别] = dt1.Rows [0] [性别]的ToString()。
                        会话[手机] = dt1.Rows [0] [MobileNo]的ToString()。
                        会话[国] = dt1.Rows [0] [国家]的ToString()。
                        会话[状态] = dt1.Rows [0] [国家]的ToString()。
                      }

和我显示这样的

  DropDownList1.Text =会话[国]的ToString()。
            DropDownList2.Text =会话[状态]的ToString()。

我能够得到DataTable中的国家和状态值。但我无法在DDL中显示它们。


解决方案

  DropDownList1.Items.Add(新的ListItem(会话[国]的ToString());
。DropDownList2.Items.Add(新的ListItem(会话[状态]的ToString());

I am displaying values from a database into a dropdownlist. but I am unable to get the corresponding values into the DDL.

if (dt.Rows.Count > 0)
            {
                DataTable dt1 = new DataTable();
                dt1 = bll.getnewid(TextBox1.Text);

                    if (dt1.Rows.Count > 0)
                    {

                        Session["pid"] = dt1.Rows[0]["NewidColumn"].ToString();
                        Session["email"] = dt1.Rows[0]["EmailID"].ToString();
                        Session["gender"] = dt1.Rows[0]["Gender"].ToString();
                        Session["mobile"] = dt1.Rows[0]["MobileNo"].ToString();
                        Session["country"] = dt1.Rows[0]["Country"].ToString();
                        Session["state"] = dt1.Rows[0]["State"].ToString();
                      }

and I am displaying like this

   DropDownList1.Text = Session["country"].ToString();
            DropDownList2.Text = Session["state"].ToString();

I am able to get the country and state values in the datatable. but I am unable to display them in the DDL.

解决方案

DropDownList1.Items.Add(new ListItem(Session["country"].ToString()); 
DropDownList2.Items.Add(new ListItem(Session["state"].ToString());

这篇关于显示一个DropDownList DB值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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