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 = (CheckBox)dgi.FindControl("bookedChkBox");

try

{

availabilityBLC.AddAvailability();

}

catch (Exception exception)

{

0
Pmillio
12/1/2008 10:43:25 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
3041 Views

Similar Articles

[PageSpeed] 50

You have to use the text property to get the value:

 

1    availabilityBLC.Availability.AvailabilityDay =((Label)dgi.FindControl("lblDay")).Text;
2    availabilityBLC.Availability.AvailabilityPrice = ((TextBox)dgi.FindControl("priceTxt")).Text;
3    
4    availabilityBLC.Availability.BBooked = ((CheckBox)dgi.FindControl("bookedChkBox")).Checked;
 

Please remember to click “Mark as Answer” so I know if my answer was good enough for you. Thanks.
0
Erwin21
12/1/2008 10:50:30 AM

Hi thanks for responding, i get the following error on this line; "Error 1 Cannot implicitly convert type 'string' to 'float' 

availabilityBLC.Availability.AvailabilityPrice = ((TextBox)dgi.FindControl("priceTxt")).Text;

What can i do to change that?

0
Pmillio
12/1/2008 11:02:22 AM
Reply:

Similar Artilces:

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

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

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

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

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

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

Having an error: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'.
Error Message: Compiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'. Line 13: myGetRandom.RetrieveDetails(lblQuestion.text, lblAnswers.text, lblViewCount.text, lblLastUpdated.text) Sub Page_Load Dim myGetRandom as new GetRandom myGetRandom.RetrieveDetails(lblQuestion.text, lblAnswers.text, lblViewCount.text, lblLastUpdated.text) End Sub Code behind Sub RetrieveDetails(lblQuestion as label, _ lblAnswers as label, _ lblViewCount as label, _ lblLastUpdated as...

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 = "...

Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap'.
 Hello,         I receive this error "System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap" when I try to find the Sitemap control.  ...            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />            <asp:ListView ID="ListView1" runat="server">            <LayoutTemplate>    ...

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

Error: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label
Here is the code:Dim dato_start_2 as DateTime Dim varighet_str as string Dim dato_differanse as string dato_start_2 = tabell_2.Rows(DataGrid1.SelectedIndex).Item("dato_tid_sendt") dato_differanse = DateDiff(DateInterval.Day, dato_start_2, now) Label12 = "" & dato_differanse & ""  ........and theCompiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'.Why and how?RegardsLars/Norway To set a text for a Label you need to use its Text property, in your code you try to set the Label to a Text and that is the reason why you g...

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

Web resources about - Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string' #2 - asp.net.presentation-controls

Resources last updated: 12/10/2015 9:24:29 PM