0

データベースの値をドロップダウンリストに表示しています。しかし、対応する値を 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();
                      }

そして、私はこのように表示しています

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

データテーブルで国と州の値を取得できます。しかし、それらを DDL に表示できません。

4

6 に答える 6

1
DropDownList1.Items.Add(new ListItem(Session["country"].ToString()); 
DropDownList2.Items.Add(new ListItem(Session["state"].ToString());
Dropdownlist2.databind();
Dropdownlist1.databind();
于 2012-08-23T09:30:59.597 に答える
1
DropDownList1.Items.Add(new ListItem(Session["country"].ToString()); 
DropDownList2.Items.Add(new ListItem(Session["state"].ToString());
于 2012-08-23T09:13:45.847 に答える
0

このようにしてみてください

   DropDownList1.Items.Add("yourvalue");
   DropDownList1.Items.Add(Session["country"].ToString());
于 2012-08-23T09:31:07.690 に答える
0

このコードを試してください:

DropDownList1.Items.Insert(0, new ListItem(Session["country"].ToString(), "0"));
DropDownList1.DataBind();

DropDownList2.Items.Insert(0, new ListItem(Session["state"].ToString(), "0"));
DropDownList2.DataBind();
于 2012-08-23T09:34:30.557 に答える
0

セッションを使用する必要性は何ですか..? 代わりにこれを試してください..うまくいくことを願っています。このコード行 (dt1 = bll.getnewid(TextBox1.Text);) の後、セッションの代わりにこの 2 行を使用します。

DropDownList1.DataSource=dt1;
DropDownList1.DataTextField="Country";
DropDownList1.DataValueField="Country";
DropDownList1.DataBind();
DropDownList2.DataSource=dt1;
DropDownList2.DataValueField="Country";
DropDownList2.DataValueField="Country";
DropDownList2.DataBind();
于 2012-08-23T09:35:04.280 に答える
0

SelectedValueドロップダウンリストのまたはSelectedIndexプロパティを設定する必要があります。

于 2012-08-23T09:13:33.903 に答える