change grid value

5 posts, 0 answers
  1. Lisa
    Lisa avatar
    43 posts
    Member since:
    Jul 2012

    Posted 18 Jul 2012 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Jul 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lisa
    Lisa avatar
    43 posts
    Member since:
    Jul 2012

    Posted 19 Jul 2012 Link to this post

    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.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Jul 2012 Link to this post

    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.
  6. Suresh
    Suresh avatar
    2 posts
    Member since:
    Jun 2016

    Posted 16 Aug in reply to Shinu Link to this post

    Yes,The above solution works fine.

     

    Thanks

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017