如何解决这个indexoutofrange异常plz帮助我

如何解决这个indexoutofrange异常plz帮助我

本文介绍了如何解决这个indexoutofrange异常plz帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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

========



CS Code
========

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();
        //}
    }
}





我尝试过:



plz帮助我解决这个异常如何处理



What I have tried:

plz help me for this exception how can i handle

推荐答案


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





我假设您的索引变量出现问题。



I assume that there something going wrong with your index variable.



这篇关于如何解决这个indexoutofrange异常plz帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:55