单击按钮后,GridView2_RowDataBound将触发两次

时间:2016-05-20 08:05:29

标签: c# html asp.net gridview

  

GridView2_RowDataBound在按钮点击后触发两次... gridview的奇怪行为...

     

我想要做的是总结列值并在页脚中显示...但不是一次添加它... RowDataBound将值添加两次...显示预期结果的两倍。< / p>      

这是我的GRIDVIEW :::

的HTML代码
<asp:GridView ID="GridView2" Width="100%" GridLines="None" AllowSorting="True" AutoGenerateColumns="False"  
   CssClass="table"  HeaderStyle-CssClass="th" RowStyle-CssClass="td" runat="server"CellPadding="4"    
        OnRowDataBound="GridView2_RowDataBound" ShowFooter="true" AllowPaging="False"  >
                            <AlternatingRowStyle />
                            <Columns>
                            <asp:TemplateField  HeaderText="Count" >
                            <ItemTemplate>
                            <asp:Label ID="Labelcalls" runat="server" Text='<%#Eval("calls") %>'></asp:Label>
                           </ItemTemplate>
                           <HeaderStyle ></HeaderStyle>
                           <ItemStyle ></ItemStyle>
                           <FooterTemplate>
                           <asp:Label ID="calls" runat="server" />
                           </FooterTemplate>
                           </asp:TemplateField>
                           <asp:TemplateField  HeaderText="Minutes" >
                           <ItemTemplate>
                           <asp:Label ID="Labelmins" runat="server" Text='<%#Eval("minutes") %>'></asp:Label>
                           </ItemTemplate>
                           <HeaderStyle ></HeaderStyle>
                           <ItemStyle ></ItemStyle>
                           <FooterTemplate>
                           <asp:Label ID="min" runat="server" />
                          </FooterTemplate>
                           </asp:TemplateField>
                           </Columns>
                           </asp:GridView>
  

这是我对RowDataBound :::

的代码隐藏
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "calls"));

    }
    if (e.Row.RowType == DataControlRowType.Footer)
    {
        Label lblTotalPrice = (Label)e.Row.FindControl("calls");
        lblTotalPrice.Text = total.ToString();

    }
}

0 个答案:

没有答案