Import Excel to corresponding defined columns of gridview

2 posts, 1 answers
  1. Sree
    Sree avatar
    30 posts
    Member since:
    Dec 2012

    Posted 04 Jan 2013 Link to this post

    Hello Team

    I have a requirement where i have radgridview which is having 5 predefined columns , i need to upload data into these fields from excel

    i have used the following code to populate the columns from excel, but they are adding next to the predefined columns, i need to map the grid columns to excel columns, how can i achieve this


    i need to populate the above values  (with out headertext ) from excel  into the corresponding columns of grid,

    from the above code i am adding auto generate columns to grid, but i want these data to be populated in the corresponding columns  any help????
  2. Answer
    Julian Benkov
    Julian Benkov avatar
    1135 posts

    Posted 08 Jan 2013 Link to this post

    Hello Lakshmi,

    To reuse the existing RadGridView columns with the DataSource, you should map the ColumnName from the DataTable object to RadGridView Columns FieldName property. Here is a sample based on your code snippet:

    DataTable table = data.Tables[0];
    gridView.ColumnCount = 5;
    gridView.AutoGenerateColumns = false;
    int index = 0;
    foreach (DataColumn col in table.Columns)
        this.gridView.Columns[index].FieldName = col.ColumnName;
    gridView.DataSource = table;

    Please keep in mind that the DataTable.Columns Count must be equal to the count of RadGridView columns.

    I hope this helps.

    All the best,
    Julian Benkov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. DevCraft R3 2016 release webinar banner
Back to Top