将GridView Column的总计添加到标签中

时间:2014-12-09 01:02:42

标签: c# asp.net

我正在尝试将一行的数字添加到gridview之外的标签中。我该怎么做?

这是我的gridview代码:

<asp:GridView ID="GridView1" runat="server" Width="539px" BackColor="White"  BorderColor="#DEDFDE"  BorderStyle="Double" OnRowDeleting="OnRowDeleting" BorderWidth="1px"  CellPadding="4" ForeColor="Black" GridLines="Vertical"  CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" Font-Size="Small"  >
                                        <AlternatingRowStyle BackColor="White" />
                                        <Columns>
                                            <asp:TemplateField HeaderText="Action" HeaderStyle-HorizontalAlign="Center" ShowHeader="False">
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="Delete" Height="22px" ImageUrl="~/images/dialog-close.png" onclientclick=" return confirm('Are you want to Delete this Item?');" Text="Delete" Width="22px" />
                                                </ItemTemplate>

<HeaderStyle HorizontalAlign="Center"></HeaderStyle>

                                                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                            </asp:TemplateField>
                                        </Columns>
                                        <FooterStyle BackColor="#CCCC99" />
                                        <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
                                        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                                        <RowStyle BackColor="#F7F7DE" />
                                        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                                        <SortedAscendingCellStyle BackColor="#FBFBF2" />
                                        <SortedAscendingHeaderStyle BackColor="#848384" />
                                        <SortedDescendingCellStyle BackColor="#EAEAD3" />
                                        <SortedDescendingHeaderStyle BackColor="#575357" />
        </asp:GridView>

以下是Gridview Rows:

                dr["PartNumber"] = dtparts.Rows[i]["PartNumber"];
                dr["Qty"] = qty;
                dr["Price"] = priceff;
                dr["ExtPrice"] = "$" + Convert.ToDouble(qty) * Convert.ToDouble(pricedb);

                dttemp.Rows.Add(dr);

1 个答案:

答案 0 :(得分:0)

您可以对RowDataBound事件中的总计求和。然后,取出该总和并将其分配给您的标签。看起来有一些例子...... here is one