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

MS excel as Radgrid datasource

4 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ruby
Top achievements
Rank 1
Ruby asked on 01 Oct 2012, 09:25 PM
I am using RadGrid with excel spreadsheet as the datasource, the data is displaying correctly in my grid.
But, while Adding new record/inserting data to excel spreadheet. I am not sure how to do that.
I have seen few examples but they are all showing exporting data to excel. But my requirement is just to add data to speadsheet from RadGrid

I am pulling data from the spreadsheet using the following code
   

 

Protected Sub uxRGMembersCleanup_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles uxRGMembersCleanup.NeedDataSource
      Dim cnstr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Server.MapPath("~/App_Data/Test_Members.xlsx") & ";" & "Extended Properties=Excel 12.0"
      Dim oledbConn As New OleDbConnection(cnstr)
      Dim strSQL As String = "SELECT * FROM [Test_Members$]"
      Dim cmd As New OleDbCommand(strSQL, oledbConn)
      Dim ds As New DataSet()
      Dim da As New OleDbDataAdapter(cmd)
      da.Fill(ds)
      uxRGMembersCleanup.DataSource = ds
      'uxRGMembersCleanup.DataBind()
  End Sub

 

 

4 Answers, 1 is accepted

Sort by
0
Ruby
Top achievements
Rank 1
answered on 01 Oct 2012, 09:36 PM
My aspx code :
<telerik:RadGrid ID="uxRGMembersCleanup" runat="server" GridLines="Both" AllowAutomaticInserts="true" 
                   AllowSorting="True" AllowPaging="True" PageSize="10"  Width="50%" DataSourceID="SessionDataSource1"
>
  
                        <HeaderContextMenu EnableTheming="True">
                        <CollapseAnimation Duration="200" Type="OutQuint" />
                    </HeaderContextMenu>  
                      <MasterTableView AutoGenerateColumns="False"  EditMode="InPlace" CommandItemDisplay="Top" DataKeyNames="MEMBER" DataSourceID="SessionDataSource1"
>
  
                           <RowIndicatorColumn>
                            <HeaderStyle Width="30px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                          <Columns>    
                            <telerik:GridBoundColumn DataField="Member" HeaderText="MEMBER" SortExpression="MEMBER"
                                                     UniqueName="MEMBER">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name" HeaderText="NAME" SortExpression="NAME"
                                                     UniqueName="NAME">
                            </telerik:GridBoundColumn>
               
                        </Columns>
                    </MasterTableView>
                    <FilterMenu EnableTheming="True">
                        <CollapseAnimation Duration="200" Type="OutQuint" />
                    </FilterMenu>
                </telerik:RadGrid>
0
Daniel
Telerik team
answered on 05 Oct 2012, 08:18 AM
Hello Ruby,

You can find some examples here:
Read and Write data in Excel 2003 and Excel 2007 using Oledb
How to update data in Excel file using OLEDB
How to insert data to Excel file using OLEDB

Let me know if you need more information.

Best regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Otto Neff
Top achievements
Rank 2
answered on 21 Jun 2013, 08:26 AM
Hi there,
I did a new version of Sample using Telerik RadGrid with Excel as DataSource:

http://webapps-in-action.com/post/Excel-(xlsxlsx)-as-DataSource-for-Telerik-RadGrid-or-any-other-ASPNET-Control

Cheers Otto.
0
Daniel
Telerik team
answered on 25 Jun 2013, 11:14 AM
Hello Otto,

Thank you for sharing your code with our community. If you want to make it easily accessible and easy to find I would recommend that you submit it as a code-library project here.
Telerik Code Library

Regards,
Daniel
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Ruby
Top achievements
Rank 1
Answers by
Ruby
Top achievements
Rank 1
Daniel
Telerik team
Otto Neff
Top achievements
Rank 2
Share this question
or