下拉列表中的选定值

本文关键字:下拉列表 | 更新日期: 2023-09-27 18:01:57

ddlType.DataSource = ObjComplaintReportFormBLL.ComplaintType();
      ddlType.DataTextField = "ComplaintType_Name";
      ddlType.DataValueField = "complainttype_id";
      ddlType.DataBind();
     ddlType.Items.Insert(0, "All");

ObjComplaintReportFormBLL.ComplaintType((返回ComplaintType_Name,complaittype_id

All是下拉列表的默认值现在我应该如何将此列表项"All"的值设置为0(int(我可以ddlType.Items[0].value = "0".但这是一个字符串

谢谢Sun

下拉列表中的选定值

更换

ddlType.Items.Insert(0, "All");

带有

ddlType.Items.Add(new ListItem(0,"All"));

通过使用Insert,您将文本"All"作为下拉列表中的第一个选项,值为"(空字符串(。要使"0"成为"全部"项目的价值,请提供ListItem:

ddlType.Items.Add(new ListItem("0", "All"));

或者,也许更接近你想要做的事情,这将在列表的开头插入你的"全部"项目:

ddlType.Items.Insert(0, new ListItem("0", "All"));

然后:

ddlType.SelectedValue = "0";

您可以将listItem对象传递给ddlType.Items.Insert方法,而不是传递字符串值,例如

ListItem liItem = new ListItem("All","0");
ddlType.Items.Insert(0,liItem);