开发者

Binding Dropdownlist Values using Dictionery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜