This is a migrated thread and some comments may be shown as answers.

[Solved] Custom Export To Excel

1 Answer 227 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kiresh
Top achievements
Rank 1
Kiresh asked on 27 May 2013, 12:34 PM
Hello everyone ,
i have done with Export To Excel  but now i need some customization in that here is scenario,

when i click on Button ExportToExcel i need one Popup in that i want to List Out all Grid Column Name with CheckBox , where i can Check some of them and then press ok it will export file with that many of selected column from column.


Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 May 2013, 05:08 AM
Hi,
Try the following code snippet to achieve the scenario.

ASPX:
<telerik:RadWindowManager ID="win" runat="server">
  <Windows>
   <telerik:RadWindow ID="window1" runat="server">
     <ContentTemplate>
       <asp:CheckBoxList ID="chkList" runat="server">
       </asp:CheckBoxList>
        <br />
       <asp:Button ID="OKButton" runat="server" Text="OK" OnClick="OKButton_Click" />
      </ContentTemplate>
   </telerik:RadWindow>
 </Windows>
</telerik:RadWindowManager>

C#:
protected void excelbtn_Click(object sender, EventArgs e)
  {
     /*To add colulmns in a checkboxlist*/
      DataTable dtcol = new DataTable();
      dtcol.Columns.Add("Names", typeof(string));
      foreach (GridColumn col in grid1.Columns)
      {
          string value = col.UniqueName.ToString();
          dtcol.Rows.Add(value);
      }
      chkList.DataSource = dtcol;
      chkList.DataTextField = "Names";
      chkList.DataValueField = "Names";
      chkList.DataBind();
      window1.VisibleOnPageLoad = true;
   }
  /*OK button click to export selected columns*/
 protected void OKButton_Click(object sender, EventArgs e)
    {
       foreach (ListItem li in chkList.Items)
       {
          if (li.Selected == false)
         {
             grid1.MasterTableView.GetColumn(li.Text).Visible = false;
         }
       }
       grid1.MasterTableView.ExportToExcel();
    }

Thanks,
Princy.
Tags
Grid
Asked by
Kiresh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or