【问题标题】:How to pass details in a Gridview to a report?如何将 Gridview 中的详细信息传递给报表?
【发布时间】:2016-08-18 10:40:04
【问题描述】:

我有一个从数据库中获取的数据网格视图。在表格中,有很少的列可以从文本框和下拉列表获取用户输入。我想将所有这些数据传递到一个水晶报表而不插入数据库并在报表中打印为表格。 行数 可以更改。所以我不能设计里面的桌子。所以我想打印水平线来分隔细节(不需要垂直线)。我该怎么办?
在这里我添加了我的 aspx 代码

aspx 代码

<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
                    runat="server" AutoGenerateColumns="False" Style="margin-left: 20px; margin-right: 20px;
                    margin-top: 10px" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
                    BorderColor="#999999" BorderStyle="Solid" BorderWidth="2px">
                    <%--OnRowDataBound="OnRowDataBound" OnRowEditing="OnRowEditing--%>
                    <Columns>
                        <asp:BoundField DataField="chdrnum" HeaderText="Client Num" ItemStyle-Width="90">
                            <ItemStyle Width="90px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="CCDATE" HeaderText="Risk Date" ItemStyle-Width="90">
                            <ItemStyle Width="90px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="SUMIN" HeaderText="Sum Assured" ItemStyle-Width="90">
                            <ItemStyle Width="90px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="SINSTAMT06" HeaderText="Premiums" ItemStyle-Width="90">
                            <ItemStyle Width="90px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="PTDATE" HeaderText="Next Due Date" ItemStyle-Width="90">
                            <ItemStyle Width="90px" />
                        </asp:BoundField>
                        <asp:TemplateField HeaderText="Surrender Value">
                            <ItemTemplate>
                                <asp:TextBox ID="txtSVal" runat="server" Style="width: 100px; margin-left: 5px; background-color: Transparent"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Loan Outstanding">
                            <ItemTemplate>
                                <asp:TextBox ID="txtLoan" runat="server" Style="width: 110px; margin-left: 5px; background-color: Transparent"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Age Admitted">
                            <ItemTemplate>
                                <asp:DropDownList ID="ddlAge" runat="server" Style="width: 80px; margin-left: 5px;
                                    background-color: Transparent">
                                    <asp:ListItem Text="- Select -" Value="- Select -" />
                                    <asp:ListItem Text="Yes" Value="Yes" />
                                    <asp:ListItem Text="No" Value="No" />
                                </asp:DropDownList>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <HeaderStyle BackColor="#3AC0F2" ForeColor="White" />
                    <AlternatingRowStyle BackColor="#3AC0F2" />
                </asp:GridView>

【问题讨论】:

  • 在水晶报表中使用交叉表
  • 我想在gridview中传递数据。设计不是问题

标签: c# asp.net gridview crystal-reports


【解决方案1】:

首先将您的 Gridview 转换为 Datatable

 protected void btnExportCrstalReport_Click(object sender, EventArgs e)
    {
        DataTable _datatable = new DataTable();
        for (int i = 0; i < grdReport.Columns.Count; i++)
        {
            _datatable.Columns.Add(grdReport.Columns[i].ToString());
        }
        foreach (GridViewRow row in grdReport.Rows)
        {
            DataRow dr = _datatable.NewRow();
            for (int j = 0; j < grdReport.Columns.Count; j++)
            {
                if (!row.Cells[j].Text.Equals("&nbsp;"))
                    dr[grdReport.Columns[j].ToString()] = row.Cells[j].Text;
            }

            _datatable.Rows.Add(dr);
        }
        ExportDataTableToPDF(_datatable);
    }

这里将Dataable绑定到水晶报表

 void ExportDataTableToPDF(Datatable _datatable)
   {
   }

【讨论】:

  • 感谢您的回答。我会试试这个
  • 什么是“grdReport”?
  • grdReport 是 Gridview
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-08
  • 2014-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多