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();
精彩评论