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

change grid value

5 Answers 91 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lisa
Top achievements
Rank 1
Lisa asked on 18 Jul 2012, 04:38 PM
Hello,
I try to change values of a cell in a radGrid before exporting the grid to Excel as shown below. For testing purpose I set the value to "123". After exporting, Excel does not show "123" at all. Why is that? I try to Rebind() before exporting and it doesn't work either.

Private Sub exp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exp.Click
       For Each rowItem As GridDataItem In RadGrid1.Items
            rowItem ("E").Text = "123"
        Next
       RadGrid1.MasterTableView.ExportToExcel()
End Sub

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 19 Jul 2012, 04:42 AM
Hello Lisa,

Try the following code to achieve your scenario.
VB:
Protected Sub RadGrid1_ExportCellFormatting(sender As Object, e As ExportCellFormattingEventArgs)
    If (e.FormattedColumn.UniqueName) = "UniqueName" Then
        e.Cell.Text = "Some text"
    End If
End Sub

Thanks,
Shinu.
0
Lisa
Top achievements
Rank 1
answered on 19 Jul 2012, 08:29 PM
I use ImageButton and when the button is clicked it executes the event handler which takes System.EventArgs as one of the arguments. It doesn't take ExportCellFormattingEventArgs as an argument. So how can I make your example fit in here with the ImageButton? Thanks.
0
Shinu
Top achievements
Rank 1
answered on 20 Jul 2012, 04:23 AM
Hello Lisa,

Here is the sample code that I tried to export in an external button click in which ExportCellFormatting event is firing and the text is changed on exporting.
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"  onexportcellformatting="RadGrid1_ExportCellFormatting">
 <ExportSettings ExportOnlyData="false" IgnorePaging="true" Excel-Format="Html"></ExportSettings>
   <MasterTableView>
    </Columns>
      <telerik:GridBoundColumn UniqueName="EmployeeID"  DataField="EmployeeID" HeaderText="EmployeeID"></telerik:GridBoundColumn>
      <telerik:GridBoundColumn UniqueName="LastName"  DataField="LastName" HeaderText="LastName"></telerik:GridBoundColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid>
C#:
protected void imgExport_Click(object sender, ImageClickEventArgs e)
{
  RadGrid1.MasterTableView.ExportToExcel();
  RadGrid1.Rebind();
}
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
  if ((e.FormattedColumn.UniqueName) == "LastName")
  {
     e.Cell.Text = "some text";
  }
}

Thanks,
Shinu.
0
Suresh
Top achievements
Rank 1
answered on 17 Aug 2016, 04:30 AM

Yes,The above solution works fine.

 

Thanks

0
Geoff
Top achievements
Rank 1
answered on 12 Mar 2019, 05:26 PM

Worked for me,

Thanks

Geoff

 

Tags
General Discussions
Asked by
Lisa
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Lisa
Top achievements
Rank 1
Suresh
Top achievements
Rank 1
Geoff
Top achievements
Rank 1
Share this question
or