我正在将查询的字典结果集绑定到字典以填充下拉列表,但我想为下拉列表添加默认值
我尝试先添加该值,但它不起作用。我也尝试过最后添加它并反转它。
<asp:DropDownList ID="ddl_Reason" runat="server" OnInit="ddl_Reason_Init"></asp:DropDownList>
protected void ddl_Reason_Init(object sender, EventArgs e)
{
ddlreason = (DropDownList)sender;
ddlreason.DataSource = sr.ReturnReason();
ddlreason.DataTextField = "Value";
ddlreason.DataValueField = "Key";
ddlreason.DataBind();
//ddlreason.Items.Insert(0, new ListItem("--Select Reason--","0"));
}
var ddlreasonpop = (from a in pc.tbl_Reason
select new { a.Reason, a.Id }).ToDictionary(a => a.Id, a => a.Reason);
Dic_reason = ddlreasonpop;
Dic_reason.Add(0, "--Select Reason--");