Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C#
Compiler Error Message: CS0266: Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)

Source Error:


Line 270:
Line 271:            
Line 272:            n_sno = Convert.ToInt64(((TextBox)(row.Cells[1].Controls[0])).Text);
Line 273:            n_date = ((TextBox)(row.Cells[2].Controls[1])).Text.Trim();
Line 274:            n_c_ref = ((TextBox)(row.Cells[3].Controls[2])).Text.Trim();


Source File: c:\Users\bhushan.COMTEK\Desktop\Halo Convert in Publication\PublicationWeb\Indent.aspx.cs    Line: 272


plz check this code.......
firstly i'm taking old values then new values then new value inserted in gridvalue but when i'm taking new serialnumber: show exception- Index out of range.

Error line is this : n_sno = Convert.ToInt16(((TextBox)(row.Cells[1].Controls[0])).Text);
C#
protected void grid_indent_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    try
    {
        // retrieve the table from the session object...
       // DataTable dt = (DataTable)Session["grid_value"];

        // update the values of grid...
        List<item_list> objList = (List<item_list>)Session["listdata"];

        GridViewRow row = grid_indent.Rows[e.RowIndex];
        
        o_sno = objList[row.DataItemIndex].serialnumber;
        o_date = objList[row.DataItemIndex].date;
        o_c_ref = objList[row.DataItemIndex].coderef;
        o_i_name = objList[row.DataItemIndex].item_name;
        o_inhand = objList[row.DataItemIndex].inhand;
        o_request = objList[row.DataItemIndex].newrequest;
        o_rate = objList[row.DataItemIndex].rate;
        o_amt = objList[row.DataItemIndex].amount;
     
        n_sno = Convert.ToInt16(((TextBox)(row.Cells[1].Controls[0])).Text);
        n_date = ((TextBox)(row.Cells[2].Controls[1])).Text.Trim();
        n_c_ref = ((TextBox)(row.Cells[3].Controls[2])).Text.Trim();
        n_i_name = ((TextBox)(row.Cells[4].Controls[3])).Text.Trim();
        n_inhand = Convert.ToInt32(((TextBox)(row.Cells[5].Controls[4])).Text.Trim());
        n_request = Convert.ToInt32(((TextBox)(row.Cells[6].Controls[5])).Text.Trim());
        n_rate = ((TextBox)(row.Cells[7].Controls[6])).Text.Trim();
        n_amt = ((TextBox)(row.Cells[8].Controls[7])).Text.Trim();

        objList[row.DataItemIndex].serialnumber =n_sno;
        objList[row.DataItemIndex].date = n_date;
        objList[row.DataItemIndex].coderef = n_c_ref;
        objList[row.DataItemIndex].item_name = n_i_name;
        objList[row.DataItemIndex].inhand = n_inhand;
        objList[row.DataItemIndex].newrequest = n_request;
        objList[row.DataItemIndex].rate = n_rate;
        objList[row.DataItemIndex].amount = n_amt;
    
        grid_indent.EditIndex = -1;
        popUpData();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
    finally
    { }
}

thanks in advance...
Bhushan
Posted
v2
Comments
The error is in line Line 272:
n_sno = Convert.ToInt64(((TextBox)(row.Cells[1].Controls[0])).Text);

But the code you have written is on Convert.ToInt16().

Have a look at this article if you want to know about ways to deal with this sort of problem
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

Having reread your question actually - maybe all you needed was a pair of extra eyes :)
 
Share this answer
 
v2
Looks like n_sno was defined to be an int, i.e. a 32 bit integer variable. Hence, you need a Convert.ToInt32().
As far as your IndexOutOfRangeException is concerned, check that the row has a Cell with index 1, and that that cell has a control with index 0.
 
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