2013-11-22 76 views
0

試着發送帶有文檔名稱的郵件,然後確定哪些管理員從下拉列表中選擇,如批准/拒絕/待定 爲此,我嘗試此代碼不能隱式轉換類型'字符串'爲'System.Web.UI.WebControls.DropDownList'

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:

<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> 

但在這裏,發生在這個代碼

dropdownvalue = "Unavailable"; 

錯誤 無法隱式轉換類型「字符串」到「System.Web.UI.WebControls.DropDownList」

回答

1

你的錯誤是,在你的HTML lblvalue是一個標籤,你想投一個Dropdowm:

//HTML 
    <asp:Label ID="lblvalue" runat="server" Text='<%# Eval("ApproveID") %>' Visible = "false" /> 

//CodeBehind 
    DropDownList dropdownvalue = 
        ((DropDownList)Repeater2.Items[i].FindControl("lblvalue")); 

我認爲你正在尋找一個標籤來獲取值:

Label dropdownvalue = 
        ((Label)Repeater2.Items[i].FindControl("lblvalue")); 

但無論你想獲取和設置在下拉列表中的值:

DropDownList dropdownvalue = 
         ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4")); 

我希望你看到錯誤。

+0

在表格中,我添加了下拉式標籤。 – user2931015

+0

@ user2931015看看這條線,因爲您試圖投下一個像DropDown一樣的標籤。 –

+0

我不明白你正在試圖說 – user2931015

相關問題