CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList'

I've got another error. Don't know where this is coming from.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList'

Source Error:

Line 1:  <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="add_contact2.aspx.cs" Inherits="add_contact2" Title="Add Contact" %>
Line 2:  
Line 3:  <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

Source File: c:\Users\Alex\Documents\Visual Studio 2008\WebSites\contacts\add_contact2.aspx    Line: 1


If we can catch a baseball with our hand, we can also catch a punch because it is moving slower. Why can't we catch a punch though? We're tense.
2
acbarberi
5/28/2008 4:20:43 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

7 Replies
1958 Views

Similar Articles

[PageSpeed] 50

hi

post your code so we can monitor it for error.


Suyog
I am just using my free time,but if it helps you then my mark my post as answer
0
suyog
5/28/2008 6:59:46 AM

Hi,

Please post your code so that we figure this out

 

But you might be using the value of dropdown control what I think and what you are trying to do is might be similar to below:

You might be doing: 

String sStr = ddlDropDown;   //Will generate Error

What will work: 

String sStr = ddlDropDown.SelectedValue;    //Correct and will work

I think this will solve your problem 


Warm Regards:
Sitanshu

Please "Mark as Answer" if my post sort your problem
0
sbakshi
5/28/2008 7:09:39 AM

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="add_contact2.aspx.cs" Inherits="add_contact2" Title="Add Contact" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

<table border = "0" cellpadding = "0" cellspacing = "0" style = "font-weight: bold;">

<thead>

<tr><td colspan = "2">Add Contact</td></tr>

</thead>

<tbody style = "background-color: rgb(181, 207, 248);">

<tr>

<td id = "main_box_left">

<table border = "0">

<tr>

<td><font color=red><b>*</b></font>&nbsp;First Name: </td>

<td><asp:TextBox ID="FirstName" runat="server" width="100%"></asp:TextBox></td>

</tr>

<tr>

<td><font color=red><b>*</b></font>&nbsp;Last Name: </td>

<td><asp:TextBox id="LastName" runat="server" width="100%"></asp:TextBox></td>

</tr>

<tr>

<td>Position: </td>

<td><asp:DropDownList runat="server" id="JobTitle" width="100%"></asp:DropDownList></td>

</tr>

<tr>

<td>Title: </td>

<td><asp:DropDownList runat="server" id="Title" width="100%"></asp:DropDownList></td>

</tr>

<tr>

<td>Store #: </td>

<td><asp:DropDownList id="StoreNumber" runat="server" width="100%"></asp:DropDownList></td>

</tr>

<tr>

<td>Company: </td>

<td><asp:DropDownList id="Company" runat="server" width="100%"></asp:DropDownList></td>

</tr>

<tr>

<td>Sub Of: </td>

<td><asp:DropDownList id="cboSubOf" runat="server" width="100%"></asp:DropDownList></td>

</tr>

</table>

</td>

<td id = "main_box_right" style = "float: right;">

<table border = "0" style = "margin-left: 10px;">

<tr>

<td>Address: </td>

<td><asp:TextBox id="BusinessStreet" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>City: </td>

<td><asp:TextBox id="BusinessCity" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>State: </td>

<td><asp:DropDownList runat="server" id="BusinessState" width="100%"></asp:DropDownList></td>

</tr>

<tr>

<td>Zip: </td>

<td><asp:TextBox id="BusinessPostalCode" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>Account: </td>

<td><asp:Checkbox id="chkAccount" runat="server"></asp:Checkbox></td>

</tr>

<tr>

<td>Account Name: </td>

<td><asp:TextBox id="txtAccount" runat="server"></asp:TextBox></td>

</tr>

</table>

</td>

</tr>

<tr>

<td id="main_box_bottom" colspan=2>

<table border = "0">

<tr>

<td>Bus. Phone: </td>

<td><asp:TextBox id="BusinessPhone" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>Bus. Fax: </td>

<td><asp:TextBox id="BusinessFax" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>Cell Phone: </td>

<td><asp:TextBox id="MobilePhone" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>Email: </td>

<td><asp:TextBox id="EmailAddress" runat="server"></asp:TextBox></td>

</tr>

</table>

</td>

</tr>

<tr>

<td style="padding-top: 10px; text-align: right" colspan=2>

<asp:Button ID="cmdBack" runat="server" Text="Back" OnClick="cmdBack_Click" />

<asp:Button ID="cmdSave" runat="server" Text="Save Changes" OnClick="cmdSave_Click" />

</td>

</tr>

</tbody>

</table><br />

</asp:Content>

 

 

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

public partial class add_contact2 : System.Web.UI.Page

{

//string db = "";

DataTier data;
protected void Page_Load(object sender, EventArgs e)

{

// If Convert.ToInt16(Session("Level")) < 10 Then Response.Redirect("default.aspx")

//HttpContext.Current.

db = Server.MapPath("./contacts.mdb");

data = new DataTier(db, "Contacts");

data.SimpleComboDataBind(BusinessState, "STATE", "Name");

data.SimpleComboDataBind(JobTitle, "JOBTITLE", "Name");

data.SimpleComboDataBind(Title, "TITLE", "Name");data.SimpleComboDataBind(StoreNumber, "STORENUMS", "Name");

data.ComplexComboDataBind(cboSubOf,

"SELECT * FROM Contacts WHERE Account=True ORDER BY FirstName,LastName",

new string[] { "FirstName", "LastName" }, " ");

data.ComplexComboDataBind(Company,

"SELECT * FROM Contacts WHERE Account=True ORDER BY Company",new string[] { "Company" }, "");

}

protected void cmdSave_Click(object sender, EventArgs e)

{

if (FirstName.Text == "" || LastName.Text == "")

{

Response.Write(
"<font color=red><b>You must fill in the First Name and Last Name fields.</b><br><br>");

}

else

{

data.FirstName = FirstName.Text;

data.LastName = LastName.Text;

data.BusinessStreet = BusinessStreet.Text;

data.BusinessCity = BusinessCity.Text;

data.BusinessState = BusinessState.SelectedItem.ToString();

data.BusinessPostalCode = BusinessPostalCode.Text;

data.Account = chkAccount.Checked;

data.Company = Company.SelectedItem.ToString();

data.BusinessPhone = BusinessPhone.Text;

data.BusinessFax = BusinessFax.Text;

data.MobilePhone = MobilePhone.Text;

data.EmailAddress = EmailAddress.Text;

data.SubOf = cboSubOf.SelectedItem.ToString();

data.JobTitle = JobTitle.SelectedItem.ToString();

data.Title = Title.SelectedItem.ToString();

data.StoreNumber = StoreNumber.SelectedItem.ToString();

data.AddRecordWithData();

Response.Redirect(
"default.aspx");

}

}

protected void cmdBack_Click(object sender, EventArgs e)

{

Response.Redirect(
"default.aspx");

}

}


If we can catch a baseball with our hand, we can also catch a punch because it is moving slower. Why can't we catch a punch though? We're tense.
0
acbarberi
5/30/2008 1:17:07 AM

That's my code above there. If I comment out all of the code-behind though, it still has the error so I don't know how in the world it's happening.


If we can catch a baseball with our hand, we can also catch a punch because it is moving slower. Why can't we catch a punch though? We're tense.
0
acbarberi
5/30/2008 1:18:08 AM

hello 

this is not seems to be a coding error i suggest u to delete the page and add new one with same or different name


HAPPY CODING
http://shobhitrai.blogspot.com/
0
shobhit
5/30/2008 4:25:30 AM

Hi sure solution is just change ID of following dropdown list to any thing other than "Title"

Don't give ID as "Title" for dropdown list

<tr>

<td>

Title:

</td>

<td style="width: 154px">

<asp:DropDownList runat="server" ID="Title1" Width="100%">

 

 

</asp:DropDownList>

</td>

</tr>

I have changed it to "Title1" and it working fine on my side.

Best luck.Yes

 


Suyog
I am just using my free time,but if it helps you then my mark my post as answer
1
suyog
5/30/2008 5:19:59 AM

Thanks! You're a genius. I probably wouldn't have thought of that.


If we can catch a baseball with our hand, we can also catch a punch because it is moving slower. Why can't we catch a punch though? We're tense.
0
acbarberi
5/31/2008 3:36:34 PM
Reply:

Similar Artilces:

Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string'
I have a datagridLabel ID1 = (Label)(e.Item.FindControl("ID1")); Label Name1 = (Label)(e.Item.FindControl("Name1")); Label TableName = (Label)(e.Item.FindControl("TableName"));   No0w Iam trying to TBTableName.Text = lblTableName;                  tbid.Text = lblImageTypeID1;                   tbnameordes.Text = lblImageName1; I have tried l lbltablename.text,.tostring,convert.t...

Cannot implicitely convert type 'string' to 'System.Web.UI.WebControls.Label'
 I'm starting to make a website for users to login. Once they login, I'm showing their profile. So I populate some asp:label controls on Page_Load. My profile page (shown after the user logs in) contains: <%@ Page Language="C#" MasterPageFile="~/site.master" CodeFile="clientProfile.aspx.cs" Inherits="clientProfile" AutoEventWireup="true" Title="Car Look - Your profile" %> <asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server"> <div> &l...

Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.
Hi,  I have a formview with a dropdownlist created dynamically. i want to determine whether the dropdownlist was clicked. the code is written in the FormView1_DataBound method. I get the following error in the line below that is in italics and underlined: Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.   Here is my code: ddl_iFullname = New DropDownList ddl_iFullname.ID = "ddl_iFullname" ddl_iFullname.DataSource = ObjectDataSource3 ddl_iFullname.DataTextField = "fullname" ddl_iFullname.DataValueField = "...

ASPNET2 HELP! CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'.
Server Error in '/start-movieposters' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'. An explicit conversion exists (are you missing a cast?) Source Error: ...

Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string' #2
Hi i am getting the following error "Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string'", what am i doing wrong, my code looks like this;protected void lbtnSubmit_Click(object sender, EventArgs e) {foreach(DataGridItem dgi in dgAvailability.Items) {AvailabilityBLC availabilityBLC = new AvailabilityBLC(); availabilityBLC.Availability.AvailabilityDay =(Label)dgi.FindControl("lblDay");availabilityBLC.Availability.AvailabilityPrice = (TextBox)dgi.FindControl("priceTxt"); availabilityBLC.Availability.BBooked = (CheckB...

System.Net.Mail is giving error CS0029: Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
I'm getting an error while trying to use the wizard to create a form and than pass it the vaibles to Mail. Any help would be much appreciated. SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try {   message.From = txtEmail.Text; message.To.Add("admin1@yoursite.com"); message.Subject = "Feedback"; message.CC.Add("admin1@yoursite.com"); message.CC.Add("admin2@yoursite.com"); message.IsBodyHtml = false; message.Body = txtMessage.Text; smtpClient.Send(message); lblStatus.Text = "Email successfully sent."; } catch (Exception ex) { lbl...

Error: Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField'
Hello, I am getting the following error during compiliation. Any suggestions to fix it. Thanks. Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField' protected void gvEvents_RowCommand(Object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvEvents.Rows[index]; string sID; ButtonField btn; if (selectedRow.RowType == DataControlRowType.DataRow) { sID = ((ButtonField)selectedRow.FindControl("ID")).DataTextFi...

Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox'
I am attempting to "Update" a field in a Datagrid, but no matter what I do (Using either Label or Text Boxes)  I keep getting the same error: Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox' The Error is highlighted below in the Sub... <==THE FIELD THAT CALLS THE ERROR  Any help would be greatly appreciated !!! Thanks !!   The code is as follows... <table border=0 height=210 bordercolor=olive ><tr valign=top><td> <asp:datagrid id="FacilityDataGrid"...

Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.TextBox'
I have a new page (wireframe) based on the User_Create page in the Time Tracker starter kit.  I have no code in the code behind page.  What might be causing this error?  This newbie needs help. I had a TextBox control named "Title" which appearantly conflicted with the page title. thanks!!! ...

Cannot implicitly convert type 'Login' to 'System.Web.UI.WebControls.Login'
hello  i have got this error on this part of code :protected void Wizard1_NextButtonClick(object sender, System.Web.UI.WebControls.WizardNavigationEventArgs e) {if (e.CurrentStepIndex == 0) {System.Web.UI.WebControls.Login l = (Login)Wizard1.FindControl("Login1");if (Membership.ValidateUser(l.UserName, l.Password)) { FormsAuthentication.SetAuthCookie(l.UserName, l.RememberMeSet);e.Cancel = false; } else {l.InstructionText = "Your login attempt was not successful. Please try again."; l.InstructionTextStyle.ForeColor = System.Drawing.Color.Red;e.Cancel = ...

Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.TextBox'
Can anyone tell me what this error message means, and what to do to correct it.  Here is the code that has the error:  Dim sql As Stringsql = "INSERT INTO tblConnecting (Date, Member, Name, Company, Phone, Fax, Address, NamesofAttendees, PaymentType, Email) " _ & "Values('" & Today() & "', '" & blnMember & "', '" & Me.txtName.Text & "', '" & Me.txtCompany.Text & "', '" _& Me.txtPhone.Text & "', '" & Me.txtFax.Text &...

BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'.
I have a pretty basic vb.net page that includes a listview.  (Note, this is my first time working with listview, so I may have some of the terminology wrong).  In my list view, I display all the important data for each record, and ask the user to provide a status for each record by including a radiobutton list with various responses.  At the bottom of the page is one submit button, and when the user clicks submit, I'm saving each records value based upon which response is selected in the radiobutton list. My saving of data is working,  but I'm ...

BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.TextBox'.
 Hello everyone, I receive the error in the subject when viewing this page, I can get it to work fine without the master page and only the textboxes, but that causes an error with line 11, even when the page contents do process to the form. I don`t understand the error and I would appreciate any guidance on this. Thanks for reading.1 <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %> 2 3 <script runat="server"> 4 5 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 6 Dim D...

BC30311: Value of type 'System.Web.UI.WebControls.RadioButtonList' cannot be converted to 'String'.
I have a listview that I'm working with.  Each record returned by my sql query is displayed in my list view as text, with the exception of one field, which I need to display as a radiobutton list.  I tried to set the value of the radiobutton in my codebehind, but keep getting errors.  How do I tell this radiobutton list that the value that should be selected when the page loads is equal to the value returned from my sql query?    The line in bold throws the error... How am I supposed to indicate what value to have selected when the page loads? <asp:Radi...

Web resources about - CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList' - asp.net.getting-started

Resources last updated: 1/18/2016 12:52:22 PM