Cells[3]的定义:                                        <asp:TemplateField HeaderText="Input Qty" Visible=true >
                                            <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                                            <HeaderStyle HorizontalAlign="Left" />
                                            <ItemTemplate>
                                                <span style="height: 10px">
                                                    <asp:Label ID="lblInQty" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.input_qty") %>'>
    </asp:Label></span>
                                            </ItemTemplate>
                                        </asp:TemplateField> 
RowDataBound事件:
protected void grdYield_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Int32 nIn = 0;
            if ((e.Row.RowIndex >=0)&&(e.Row.RowType == DataControlRowType.DataRow))
            {
                nIn = nIn + Convert.ToInt32(e.Row.Cells[3].Text);            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[4].Text = nIn.ToString();
            } 
            
        }帮忙看下为什么Convert.ToInt32(e.Row.Cells[3].Text)的值一直是空的,可是实际上是有值的

解决方案 »

  1.   

    这是因为楼主用的是模板列,所以通过Cells[3]是不能拿到值的。应该这样 if ((e.Row.RowIndex >=0)&&(e.Row.RowType == DataControlRowType.DataRow)) 
                { 
                    Label labelText=(Label)e.Row.FindControl("lblInQty");
                    
                    nIn = nIn + Convert.ToInt32(labelText.Text);             } 这样就对了
      

  2.   

    非常谢谢,弄好了,
    在问个问题,我想把lblSN.Text=0.01556的格式改为1.55% 改怎么写啊,我只知道GridView中的{0:N2}
      

  3.   

    string ss = string.Format("{0:P2}", 0.01556);