C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Error


Posted Date: 28 Aug 2008      Posted By: Elz      Member Level: Gold     Points: 1   Responses: 5



Hi all
what thz error how to correct thiz
Cannot implicitly convert type 'int' to 'System.Web.UI.WebControls.Label'

tot is of int and total label


<asp:GridView ID="GridView1" runat="server" >

<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="Label1" runat=server> </asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>
My code

if(dt.rows.count>0)
{
dtrow=0;
foreach (GridViewRow row in GridView1.Rows)
{
int i=Convert.ToInt32(dt.Rows[dtrow][4].ToString());
int j=Convert.ToInt32(dt.Rows[dtrow][5].ToString());
int k=Convert.ToInt32(dt.Rows[dtrow][6].ToString());
int l=Convert.ToInt32(dt.Rows[dtrow][7].ToString());
int m=Convert.ToInt32(dt.Rows[dtrow][8].ToString());
int n=Convert.ToInt32(dt.Rows[dtrow][9].ToString());
int o=Convert.ToInt32(dt.Rows[dtrow][10].ToString());
int tot = i + j + k + l + m + n + o;
total = (Label)row.FindControl("Label1");
total=tot;
}
}






Responses

Author: Sidewinder2    28 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 1

Hi,

try this

(Label)row.FindControl("Label1").text= tot.ToString();



Author: sivapriya    28 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 3

total = (Label)row.FindControl("Label1");
total=tot;
here you r trying to assign int to label value (string).

use like this

Label total = (Label)row.FindControl("Label1");
total.Text=Convert.ToString(tot);



Author: Karthikeyan S    28 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

In your code (last four lines) the object " (Label)row.FindControl("Label1")" is returning a Label.

First check whether 'total' is an integer datatype or Label control.

Let we create a Label control named as lblTotal and total value sumed is stored in the variable 'tot'.

then correct code is:

Label total = (Label)row.FindControl("Label1"); // right side code is returing a Label control. So we created a Label control called total and we placed it in left side.
total.Text = tot.ToString(); // tot is an int and total.text is of string datatype. so we have to convert tot integer to string using ToString() function.



Author: Elz    28 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 0

thanks all


Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : check this (urgent)
Previous : regarding watermark
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use