本文介绍了gridview中的选定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



是否有任何解决方案可以在Excel中导出选定的网格视图列,

因为我找到了很多博客和解决方案关于选定的行而不是关于列,

请各位让我知道任何解决方案。



提前感谢。

HI ,

is there any solution to export selected columns of grid view in excel ,
as i found many blogs and solution about the selected rows but not about columns ,
pls guys let me know for any solution for it .

thanks in advance .

推荐答案

private void btnExportExcel_Click()
{
    Response.Clear();
    Response.Buffer = true;

    Response.AddHeader("content-disposition",
     "attachment;filename=MyData.xls");
    Response.Charset = "";
    Response.ContentType = "application/vnd.ms-excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);

    GridView1.AllowPaging = false;
    GridView1.DataBind();

    GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
    GridView1.HeaderRow.Cells[0].Style.Add("background-color", "green");
    GridView1.HeaderRow.Cells[1].Style.Add("background-color", "green");

    GridView1.HeaderRow.Cells[0].Visible = True;
    GridView1.HeaderRow.Cells[1].Visible = False;

    for (int i = 0; i < GridView1.Rows.Count;i++ )
    {
        GridViewRow row = GridView1.Rows[i];
        row.Cells[0].Visible = True;
        row.Cells[1].Visible = False;
        row.BackColor = System.Drawing.Color.White;
        row.Attributes.Add("class", "textmode");
    }

    GridView1.RenderControl(hw);
    string style = @"<style> .textmode { mso-number-format:\@; } </style>";
    Response.Write(style);
    Response.Output.Write(sw.ToString());
    Response.End();
}



这里我有硬编码(真/假),如果你需要它是动态的那么你的复选框到列的一侧和复制商店的更改它在视图中。稍后您可以从查看状态获取已检查的列。



[]


这篇关于gridview中的选定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 21:35