Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DropdownList未显示所选值_C#_Asp.net - Fatal编程技术网

C# DropdownList未显示所选值

C# DropdownList未显示所选值,c#,asp.net,C#,Asp.net,我在中继器中使用了DropDownList。它从数据库中获取名称(管理员、经理、成员)。 用户名显示正确,即使警报显示正确的数据。 但是dropdownlist.selecteditem没有效果。 两个用户都在下拉列表中显示admin作为默认选定值,在db及其管理器中 protected void ListRepeaterView_ItemDataBound(object sender, RepeaterItemEventArgs e) { DropDownList selectL

我在中继器中使用了DropDownList。它从数据库中获取名称(管理员、经理、成员)。 用户名显示正确,即使警报显示正确的数据。 但是dropdownlist.selecteditem没有效果。 两个用户都在下拉列表中显示admin作为默认选定值,在db及其管理器中

protected void ListRepeaterView_ItemDataBound(object sender, RepeaterItemEventArgs e)
{



    DropDownList selectList = e.Item.FindControl("DropDownList1") as DropDownList;
    selectList.DataSource = ML.SelectAll();
    selectList.DataTextField = "Designation";
    selectList.DataValueField = "EmployeeID";

    selectList.DataBind();


    HiddenField Designation = (HiddenField)e.Item.FindControl("hdnDesignation");
   selectList.SelectedValue = Designation.Value.ToString();
   ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(" + Designation.Value.ToString() + ");", true);




}
.cs文件

    <asp:Repeater ID="ListRepeaterView" runat="server" OnItemDataBound="ListRepeaterView_ItemDataBound">
<ItemTemplate><tr><td>
<asp:Label ID="EmpName" runat="server" Text='<%# Eval("EmployeeName") %>'></asp:Label>
 asp:HiddenField ID="hdnProductID" Value='<%# Eval("EmployeeID") %>' runat="server" />
</td><td>
<asp:HiddenField ID="hdnDesignation" Value='<%# Eval("Designation") %>' runat="server" />
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" >
 </asp:DropDownList>
</td></tr>
<br /><br /><br />
</ItemTemplate>
</asp:Repeater>

asp:HiddenField ID=“hdnProductID”值=“”runat=“server”/



您在选择中使用“指定”作为文本字段,“员工ID”作为值字段。然后尝试根据“指定”设置选定值。这是行不通的

您可以通过文本查找默认项:

// add some error handling for cases when item cannot be found
var defaultText = Designation.Value.ToString();
selectList.Items.FindByText(defaultText).Selected = true;

“dropdownlist.selecteditem无效”。这是什么意思?@HarveySpecter数据从数据库中正确提取,有效数据显示在警报中。但此代码未设置所选项目。已完成。非常感谢..!!:)