Click here to Skip to main content
15,887,331 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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

C#
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:
ASP.NET
<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
C#
dropdownvalue = "Unavailable";

Error Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList'
Posted
Updated 24-Nov-13 2:05am
v2

Your inaptly named "dropdownvalue" is of type DropDownList which cannot be assigned a string. Did you mean
C#
dropdownvalue.SelectedItem.Value = "2" // Reject


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"...
 
Share this answer
 
v2
Comments
CHill60 24-Nov-13 8:17am    
Sorry for the overlap!
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 ...
C#
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";
 
Share this answer
 
Type of dropdownvalue is DropDownList. So you can not set string to dropdownlist.
I think you user wrong variable.
Try this
C#
if (dropdownvalue.SelectedItem.ToString() != ""){
    dropdownvalues = dropdownvalue.SelectedItem.ToString();
}else{
    dropdownvalues = "Unavailable";
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900