开发者

Binding Dropdownlist Values using Dictionery

开发者 https://www.devze.com 2023-02-10 07:46 出处:网络
My Datatable is like this ------------- ------------------ --- IDVAL ------------- ------------------ ---

My Datatable is like this

------------- ------------------ ---
 ID              VAL
------------- ------------------ ---
1                 Abc
2                 Pqr

I am adding it to Dictionary<string, string>(dt) using dt.Add(dr[0].ToString(), dr[1].ToString()) using a loop.

Now I need to bind the data to a dropdownlist I done using

ddlAccHD.DataSource = achID;
ddlAccHD.DataBind();

Output is coming

<option value="[36,asdf]">[36,asdf]</option>

Both value and text is coming. Here 开发者_高级运维36 is Value and 'asdf' is Key


Try setting the DataTextField and DataValueField properties.

ddlAccHD.DataSource = achID;
ddlAccHD.DataValueField = "Key";
ddlAccHD.DataTextField = "Value";
ddlAccHD.DataBind();
0

精彩评论

暂无评论...
验证码 换一张
取 消