导出Gridview以在Asp.net中优化数据表

时间:2017-05-31 13:01:43

标签: c# asp.net excel

我在.net中有一个gridview,需要导出到excel / datable.Problem是 它包含文本框+下拉列表。这不适用于下拉列表

public void Persist(object sender, EventArgs e)
{
       // GridViewExportUtil.Export("Customers.xls", this.grdData);

        DataTable dt = new DataTable();

        // add the columns to the datatable            
        if (grdData.HeaderRow != null)
        {

            for (int i = 0; i < grdData.HeaderRow.Cells.Count; i++)
            {
                dt.Columns.Add(grdData.HeaderRow.Cells[i].Text);
            }
        }

        //  add each of the data rows to the table
        foreach (GridViewRow row in grdData.Rows)
        {
            DataRow dr;
            dr = dt.NewRow();

            for (int i = 0; i < row.Cells.Count; i++)
            {

                dr[i] = row.Cells[i].Text.ToString();
            }
            dt.Rows.Add(dr);
}

[1]: https://i.stack.imgur.c

0 个答案:

没有答案