want to populate data in dataset from radgrid

2 posts, 0 answers
  1. sachin
    sachin avatar
    3 posts
    Member since:
    Sep 2014

    Posted 20 Oct 2014 Link to this post

    want to populate data in dataset from radgrid  , i have  tried following eas bit not working. please provide solution ASAP
    Source, DataTable)  -Getting datatable null

    2)not getting data from ITemTemplates

    le();
            foreach (GridColumn col in grdShippedOrders.Columns)
            {
                DataColumn colString = new DataColumn(col.UniqueName);
                dtRecords.Columns.Add(colString);
     
            }
            foreach (GridDataItem row in grdShippedOrders.Items) // loops through each rows in RadGrid
            {
                DataRow dr = dtRecords.NewRow();
                foreach (GridColumn col in grdShippedOrders.Columns) //loops through each column in RadGrid
                       dr[col.UniqueName] = row[col.UniqueName].Text;
                dtRecords.Rows.Add(dr);
            }
          return dtRecords;

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 20 Oct 2014 in reply to sachin Link to this post

    Hello,

    Please try with the below code snippet.

    DataTable dtRecords = new DataTable();
     
    foreach (GridColumn col in RadGrid1.Columns)
    {
        DataColumn colString = new DataColumn(col.UniqueName);
        dtRecords.Columns.Add(colString);
     
    }
    foreach (GridDataItem row in RadGrid1.Items) // loops through each rows in RadGrid
    {
        DataRow dr = dtRecords.NewRow();
        foreach (GridColumn col in RadGrid1.Columns) //loops through each column in RadGrid
        {
            if (col.ColumnType == "GridTemplateColumn")
            {
                dr[col.UniqueName] = (row.FindControl("Label1") as Label).Text;
            }
            else
            {
                dr[col.UniqueName] = row[col.UniqueName].Text;
            }
     
        }
        dtRecords.Rows.Add(dr);
    }

    <MasterTableView AutoGenerateColumns="False" DataKeyNames="Id">
        <Columns>
            <telerik:GridBoundColumn DataField="Id" HeaderText="Id" UniqueName="Id">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn UniqueName="MyColumn">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>


    OR

    <MasterTableView AutoGenerateColumns="False" DataKeyNames="Id">
        <Columns>
            <telerik:GridBoundColumn DataField="Id" HeaderText="Id" UniqueName="Id">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn UniqueName="MyColumn">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>

    DataTable dtRecords = new DataTable();
     
    foreach (GridColumn col in RadGrid1.Columns)
    {
        DataColumn colString = new DataColumn(col.UniqueName);
        dtRecords.Columns.Add(colString);
     
    }
    foreach (GridDataItem row in RadGrid1.Items) // loops through each rows in RadGrid
    {
        DataRow dr = dtRecords.NewRow();
        foreach (GridColumn col in RadGrid1.Columns) //loops through each column in RadGrid
        {
            if (col.UniqueName == "MyColumn")
            {
                dr[col.UniqueName] = (row.FindControl("Label1") as Label).Text;
            }
            else
            {
                dr[col.UniqueName] = row[col.UniqueName].Text;
            }
     
        }
        dtRecords.Rows.Add(dr);
    }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top