1

我想从我的网格视图中检索数据到我的数据表中。问题是我的网格视图有数据寻呼机,当我想将数据抓取到我的数据表时=>它只是抓取一页所以这些是我的代码:

<asp:GridView ID="GVQuery" runat="server" AllowSorting="True" CssClass="query" GridLines="None" EmptyDataText="-"

                        AllowPaging="True" PagerSettings-Mode="Numeric" DataSourceID="SqlDS" AutoGenerateColumns="False">
                        <Columns>
                            <asp:BoundField DataField="Date" DataFormatString="{0:yyyy/MM/dd}" HeaderText="Date" SortExpression="Date" />
                            <asp:BoundField DataField="Time" DataFormatString="{0:t}" HeaderText="Time" SortExpression="Time" />
                            <asp:BoundField DataField="Balance" DataFormatString="{0:c0}" HeaderText="Balance" SortExpression="Balance">
                                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Obligee" DataFormatString="{0:c0}" HeaderText="obligee" SortExpression="Obligee">
                                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Debtor" DataFormatString="{0:c0}" HeaderText="Debtor" SortExpression="Debtor">
                                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
                            </asp:BoundField>
                            <asp:BoundField DataField="DocSerial" DataFormatString="" HeaderText="DocSerial" SortExpression="DocSerial" />
                            <asp:BoundField DataField="TransactionNo" DataFormatString="" HeaderText="TransNo" ConvertEmptyStringToNull="False" SortExpression="TransactionNo" />
                            <asp:BoundField DataField="TransactionType" DataFormatString="" HeaderText="TransType" SortExpression="TransactionType" />
                            <asp:BoundField DataField="PaymentType" HeaderText="PeymentType" SortExpression="PaymentType" />
                            <asp:BoundField DataField="BranchName" DataFormatString="" HeaderText="BranchName" SortExpression="BranchName" />
                            <asp:BoundField DataField="PayerName" DataFormatString="" HeaderText="Payer" SortExpression="PayerName" />
                            <asp:BoundField DataField="DocDescription" DataFormatString="{0:0c0}" HeaderText="DocDesc" SortExpression="DocDescription" />
                        </Columns>
                        <RowStyle CssClass="query-row" />
                        <AlternatingRowStyle CssClass="query-alternate-row" />
                        <PagerStyle CssClass="pager" />
                        <SortedAscendingHeaderStyle CssClass="sorted-asc-header" />
                        <SortedAscendingCellStyle CssClass="sorted-asc" BackColor="#12184a" ForeColor="#bddded" />
                        <SortedDescendingHeaderStyle CssClass="sorted-desc-header" />
                        <SortedDescendingCellStyle CssClass="sorted-desc" BackColor="#12184a" ForeColor="#bddded" />
                        <PagerSettings FirstPageText="Start" LastPageText="End" Position="Bottom" Mode="NumericFirstLast" PageButtonCount="40" />
                        <PagerStyle CssClass="pager" />
                        <EmptyDataTemplate>
                            <p>Nothing to Show</p>
                        </EmptyDataTemplate>
                    </asp:GridView>

这就是我将数据检索到数据表的方式:

DataTable dt = new DataTable();
        for (int i = 0; i < GVQuery.Columns.Count; i++)
        {
            dt.Columns.Add("column" + i.ToString());
            dt.Columns[i].Caption = GVQuery.Columns[i].HeaderText.ToString();
        }
        foreach (GridViewRow row in GVQuery.Rows)
        {
            DataRow dr = dt.NewRow();
            for (int j = 0; j < GVQuery.Columns.Count; j++)
            {
                dr["column" + j.ToString()] = row.Cells[j].Text;
            }

            dt.Rows.Add(dr);
        }
        for (int i = 0; i < dt.Columns.Count; i++)
        {
            dt.Columns[i].ColumnName = dt.Columns[i].Caption;
        }
4

0 回答 0