无法将类型'string'隐式转换为'System.Web.UI.WebControls.DropDownList' [英] Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList'
问题描述
尝试发送包含文档名称的邮件,然后选择从下拉列表中选择的管理员,例如批准/拒绝/待定,我尝试此代码
TRYING TO SEND mail with document name and then value which admin select from dropdown like approve/reject/pending for this i try this code
Label DocName = ((Label)Repeater2.Items[i].FindControl("DocName"));
DropDownList dropdownvalue =(DropDownList)Repeater2.Items[i].FindControl("lblvalue"));
Label Label2 = ((Label)Repeater2.Items[i].FindControl("Label2"));
string docname = String.Empty;
string dropdownvalues = String.Empty;
string emailId = String.Empty;
if (DocName.Text.ToString() != ""){
docname = DocName.Text.ToString();
}else{
docname = "Unavailable";
}
if (dropdownvalue.SelectedItem.ToString() != ""){
dropdownvalues = dropdownvalue.SelectedItem.ToString();
}else{
dropdownvalue = "Unavailable";
}
HTML:
HTML:
<td>
<asp:Label ID="lblvalue" runat="server" Text='<%# Eval("ApproveID") %>' Visible = "false" />
<asp:DropDownList ID="DropDownList4" runat="server" EnableViewState="true" class="vpb_dropdown" DataTextField="ApproveType" DataValueField="ApproveID" AutoPostBack="true" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged">
<asp:ListItem Text="Pending" selected="selected" Value="3">
</asp:ListItem>
<asp:ListItem Text="Approve" Value="1">
</asp:ListItem>
<asp:ListItem Text="Reject" Value="2">
</asp:ListItem>
</asp:DropDownList>
</td>
但此处出现在此代码中
but here occurs in this code
dropdownvalue = "Unavailable";
Error Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList'
推荐答案
您的名为dropdownvalue的名称为DropDownList,不能为其指定字符串。你的意思是
Your inaptly named "dropdownvalue" is of type DropDownList which cannot be assigned a string. Did you mean
dropdownvalue.SelectedItem.Value = "2" // Reject
在你的DropDownList4中(同样,它有一个更好的名字,比如DropDownApprovalStatus)可能的值为1,2和3,对应于Approve,Reject和Pending。我看不到不可用...
In your DropDownList4 (again, can this have a better name, like DropDownApprovalStatus) has possible values of 1, 2 and 3 corresponding to "Approve", "Reject" and "Pending". I cannot see "Unavailable"...
dropdownvalue
是一个DropDownList对象。你不能给它分配一个字符串,这将毫无意义。
你实际上要做的是更改控件上显示的.Text
,所以尝试类似......
dropdownvalue
is a DropDownList object. You can't assign a string to it, that would be meaningless.
What you are actually trying to do is change the.Text
displayed on the control, so try something like ...
dropdownvalue.Text = "Unavailable"
。
注意这仅在控件上的项目列表中已有不可用时才有效。如果它不在那里你将不得不添加它。
我认为意味着做的是说
.
Note this will only work if "Unavailable" is already in the list of items on the control. If it isn't there you will have to add it.
What I think you meant to do was say
dropdownvalues = "Unavailable";
dropdownvalue的类型是DropDownList。所以你不能将字符串设置为dropdownlist。
我认为你使用了错误的变量。
试试这个
Type of dropdownvalue is DropDownList. So you can not set string to dropdownlist.
I think you user wrong variable.
Try this
if (dropdownvalue.SelectedItem.ToString() != ""){
dropdownvalues = dropdownvalue.SelectedItem.ToString();
}else{
dropdownvalues = "Unavailable";
}
这篇关于无法将类型'string'隐式转换为'System.Web.UI.WebControls.DropDownList'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!