Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
ASP.NET
<asp:gridview id="Gridview1" runat="server" emptydatatext="Data is not available" onrowdatabound="Gridview1_RowDataBound" autogeneratecolumns="false">
    <columns>
        <asp:TemplateField HeaderText="ID">
            <itemtemplate>
                <asp:TextBox ID="txtID" runat="server" Text='<%#Eval("ID") %>' />
            
        
        <asp:TemplateField HeaderText="Quantity">
            <itemtemplate>
                <asp:TextBox ID="txtQuantity" runat="server" Text='<%#Eval("Quantity","0") %>' />
            
        
        <asp:TemplateField HeaderText="Rate">
            <itemtemplate>
                <asp:TextBox ID="txtRate" runat="server" Text='<%#Eval("Rate","0") %>' />
            
        
        <asp:TemplateField HeaderText="Total">
            <itemtemplate>
                <asp:TextBox ID="txtTotal" runat="server" Text='<%#Eval("Total","0") %>' />


CS Code
========
C#
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int index=0;

        //if (e.Row.RowType >= null)
        //{
            TextBox txtRate = (TextBox)Gridview1.Rows[index].Cells[1].FindControl("txtRate");
            TextBox txtQuantity = (TextBox)Gridview1.Rows[index].Cells[2].FindControl("txtQuantity");
            TextBox txtTotal = (TextBox)Gridview1.Rows[index].Cells[3].FindControl("Total");
            int R = int.Parse(txtRate.Text);
            int Q = int.Parse(txtQuantity.Text);
            int T = int.Parse(txtTotal.Text);

            T = Convert.ToInt32(R * Q);
            txtTotal.Text = T.ToString();
        //}
    }
}


What I have tried:

plz help me for this exception how can i handle
Posted
Updated 7-Nov-16 1:38am
v3

Of course the best way is to use your debugger - it will tell you exactly what and where the problem is!!!
As for a hint: You are indexing into Rows and Cells, but how can you be sure that there are rows and cells?
 
Share this answer
 
you should try something like this and remove the Gridview1.Rows[index] code:

C#
if ((e.Row.RowType == DataControlRowType.DataRow))
{
    TextBox txtRate = e.Row.FindControl("txtRate");
}


I assume that there something going wrong with your index variable.
 
Share this answer
 
Comments
kiran kamble 14-Nov-16 2:27am    
yes i try like that also but its showing nullreference exception
kiran kamble 14-Nov-16 2:29am    
values coming on textboxs but its throwing nullreference, how can i handle this
Why don't you use Google to look up what the exception actually means. And then you take a good look at your code to fix the line where it comes from.

You don't even have to guess where the exception comes from. Every exception contains a so called stack trace that tells you from where the exception was thrown.
 
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