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

Convert asp Gridview to Telerik RadGrid

3 Answers 141 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aftab
Top achievements
Rank 1
Aftab asked on 28 Apr 2013, 12:27 PM
Kindly help me
I want to convert asp grid view to Telerik RadGrid
This is my code
i try my level best but i am unable to do this

<asp:GridView ID="grdWeeks" runat="server" AutoGenerateColumns="false" ShowFooter="false"
                                BorderColor="Transparent" ShowHeader="false" OnRowDataBound="grdWeeks_RowDataBound"
                                Width="100%">
                                <Columns>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <fieldset>
                                                <legend>
                                                    <asp:Label ID="lblWeekTitle" runat="server" Text=""></asp:Label>
                                                </legend>
                                                <table id="tblSave" runat="server" width="100%" border="0" cellpadding="0" cellspacing="0">
                                                    <tr>
                                                        <td>
                                                            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                                                <tr>
                                                                    <th style="text-align: right; background-color: #CFE2FC; height: 34px;">
                                                                        <asp:Label ID="lblHeadingTotal" runat="server" Text="TOTALS:" Style="position: relative;
                                                                            right: 84px;"></asp:Label>
                                                                        <asp:Label ID="lblWeekTotal1" runat="server" Text="9.922 €" Style="position: relative;
                                                                            right: 8px;"></asp:Label>
                                                                    </th>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <asp:GridView ID="grdWeekDetail1" runat="server" AutoGenerateColumns="false" RowStyle-CssClass="rowstyle"
                                                                            ShowHeader="false" ShowFooter="false" HeaderStyle-CssClass="header_row" AlternatingRowStyle-CssClass="alternate_row"
                                                                            GridLines="None" OnRowDataBound="grdWeekDetail1_RowDataBound" OnRowCommand="grdWeekDetail1_RowCommand"
                                                                            Width="100%">
                                                                            <Columns>
                                                                                <asp:TemplateField ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"
                                                                                    ItemStyle-Width="175">
                                                                            <ItemTemplate>
                                                                                        <div id="divDays" runat="server">
                                                                                            <asp:Label ID="lblDays" runat="server" Text="Suday 14/05/2011" Style="position: relative;
                                                                                                right: 35px;"></asp:Label>
                                                                                            <asp:LinkButton ID="lnkDays" runat="server" CommandName="order" Style="position: relative;
                                                                                                right: 35px;"></asp:LinkButton>
                                                                                        </div>
                                                                                    </ItemTemplate>
                                                                                </asp:TemplateField>
                                                                                <asp:TemplateField ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right">
                                                                                    <ItemTemplate>
                                                                                        <asp:Label ID="lblTotal" runat="server" Style="position: relative; right: 8px;"></asp:Label>
                                                                                    </ItemTemplate>
                                                                                </asp:TemplateField>
                                                                            </Columns>
                                                                        </asp:GridView>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                        <td style="width: 2px; background-color: #9c9c9c;">
                                                        </td>
                                                        <td>
                                                            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                                                <tr>
                                                                    <th style="text-align: left; background-color: #CFE2FC; height: 34px;">
                                                                        <asp:Label ID="lblWeekTotal2" runat="server" Text="9.922 €" Style="position: relative;
                                                                            left: 8px;"></asp:Label>
                                                                        <asp:Label ID="Label1" runat="server" Text="TOTALS:" Style="display: none;"></asp:Label>
                                                                    </th>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <asp:GridView ID="grdWeekDetail2" runat="server" AutoGenerateColumns="false" RowStyle-CssClass="rowstyle"
                                                                            ShowHeader="false" ShowFooter="false" HeaderStyle-CssClass="header_row" AlternatingRowStyle-CssClass="alternate_row"
                                                                            GridLines="None" OnRowDataBound="grdWeekDetail2_RowDataBound" OnRowCommand="grdWeekDetail2_RowCommand"
                                                                            Width="100%">
                                                                            <Columns>
                                                                                <asp:TemplateField ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                                                                                    <ItemTemplate>
                                                                                        <div id="divDays" runat="server">
                                                                                            <asp:Label ID="lblTotal" runat="server" Style="position: relative; left: 8px;"></asp:Label>
                                                                                        </div>
                                                                                    </ItemTemplate>
                                                                                </asp:TemplateField>
                                                                                <asp:TemplateField ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
                                                                                    ItemStyle-Width="175">
                                                                                    <ItemTemplate>
                                                                                        <asp:Label ID="lblDays" runat="server" Text="Suday 14/05/2011" Style="position: relative;
                                                                                            left: 35px;"></asp:Label>
                                                                                        <asp:LinkButton ID="lnkDays" runat="server" CommandName="order" Style="position: relative;
                                                                                            left: 35px;"></asp:LinkButton>
                                                                                    </ItemTemplate>
                                                                                </asp:TemplateField>
                                                                            </Columns>
                                                                        </asp:GridView>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                        <td style="width: 2px; background-color: #9c9c9c;">
                                                        </td>
                                                        <td>
                                                            <table width="100%" border="0" cellpadding="0" cellspacing="0" style="height: 187px;
                                                                width: 100%;" align="center">
                                                                <tr>
                                                                    <th valign="top" style="position: relative; background-color: #CFE2FC;" align="center">
                                                                        <div id="divDifference" runat="server" class="textbox115" style="width: 115px;">
                                                                            <asp:Label ID="lblDifference" runat="server" Text="00,00"></asp:Label>
                                                                        </div>
                                                                    </th>
                                                                </tr>
                                                                <tr class="rowstyle">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblSaturdayDiff" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="alternate_row">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblFridayDiff" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="rowstyle">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblThursdayDiff" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="alternate_row">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblWednesdayDiff" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="rowstyle">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblTuesdayDiff" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="alternate_row">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblMondayDiff" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="rowstyle">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblSundayDiff" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                        <td style="width: 2px; background-color: #9c9c9c;">
                                                        </td>
                                                        <td>
                                                            <table width="100%" border="0" cellpadding="0" cellspacing="0" style="height: 187px;
                                                                width: 100%;" align="center">
                                                                <tr>
                                                                    <th valign="top" style="position: relative; background-color: #CFE2FC;" align="center">
                                                                        <div id="divPercentage" runat="server" class="textbox115" style="width: 115px;">
                                                                            <asp:Label ID="lblPercentage" runat="server" Text="00,00"></asp:Label>
                                                                        </div>
                                                                    </th>
                                                                </tr>
                                                                <tr class="rowstyle">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblSaturdayPer" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="alternate_row">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblFridayPer" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="rowstyle">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblThursdayPer" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="alternate_row">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblWednesdayPer" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="rowstyle">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblTuesdayPer" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="alternate_row">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblMondayPer" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                                <tr class="rowstyle">
                                                                    <td align="center">
                                                                        <asp:Label ID="lblSundayPer" runat="server"></asp:Label>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                    </tr>
                                                </table>
                                                <table id="tblStaff" runat="server" visible="false" width="100%" border="0" cellpadding="0"
                                                    cellspacing="0">
                                                    <tr>
                                                        <th style="width: 274px;">
                                                            WEEK TOTALS:
                                                        </th>
                                                        <th>
                                                            <div class="textbox_small">
                                                                <asp:Label ID="lblIncome_WeekTotal" runat="server" Text="00,00"></asp:Label>
                                                            </div>
                                                        </th>
                                                        <th>
                                                            <div class="textbox_small">
                                                                <asp:Label ID="lblSalary_WeekTotal" runat="server" Text="00,00"></asp:Label>
                                                            </div>
                                                        </th>
                                                        <th>
                                                            <div class="textbox_small">
                                                                <asp:Label ID="lblTips_WeekTotal" runat="server" Text="00,00"></asp:Label>
                                                            </div>
                                                        </th>
                                                        <th>
                                                            <div class="textbox_small">
                                                                <asp:Label ID="lblBonus_WeekTotal" runat="server" Text="00,00"></asp:Label>
                                                            </div>
                                                        </th>
                                                        <th>
                                                            <div class="textbox_small">
                                                                <asp:Label ID="lblPenalty_WeekTotal" runat="server" Text="00,00"></asp:Label>
                                                            </div>
                                                        </th>
                                                        <th>
                                                            <div class="textbox_small">
                                                                <asp:Label ID="lblAdvance_WeekTotal" runat="server" Text="00,00"></asp:Label>
                                                            </div>
                                                        </th>
                                                        <th style="width: 12px;">
                                                        </th>
                                                        <th>
                                                            <div class="textbox_small">
                                                                <asp:Label ID="lblLate_WeekTotal" runat="server" Text="00,00"></asp:Label>
                                                            </div>
                                                        </th>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="10">
                                                            <asp:GridView ID="grdSalaries" runat="server" AutoGenerateColumns="false" GridLines="Vertical"
                                                                RowStyle-CssClass="rowstyle" ShowFooter="false" HeaderStyle-CssClass="header_row"
                                                                AlternatingRowStyle-CssClass="alternate_row" OnRowDataBound="grdSalaries_RowDataBound"
                                                                Width="100%">
                                                                <Columns>
                                                                    <asp:TemplateField HeaderText="Date" ItemStyle-Width="150">
                                                                        <ItemTemplate>
                                                                            <div id="divDaysForSalaries" runat="server">
                                                                                <asp:Label ID="lblDays" runat="server" Style="position: relative; left: 8px;" Text="<%#Bind('DayType') %>"></asp:Label>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Position" ItemStyle-Width="110">
                                                                        <ItemTemplate>
                                                                            <div id="divDays2" runat="server">
                                                                                <asp:Label ID="lblPosition" runat="server" Style="position: relative; left: 8px;"
                                                                                    Text="<%#Bind('position') %>"></asp:Label>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Income" ItemStyle-Width="70">
                                                                        <ItemTemplate>
                                                                            <div id="divDays3" runat="server">
                                                                                <asp:Label ID="lblIncome" runat="server" Style="position: relative; left: 8px;" Text="<%#Bind('income') %>"></asp:Label>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Salary" ItemStyle-Width="70">
                                                                        <ItemTemplate>
                                                                            <div id="divDays4" runat="server">
                                                                                <asp:Label ID="lblSalary" runat="server" Style="position: relative; left: 8px;" Text="<%#Bind('Salary') %>"></asp:Label>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Tips" ItemStyle-Width="70">
                                                                        <ItemTemplate>
                                                                            <div id="divDays5" runat="server">
                                                                                <asp:Label ID="lblTips" runat="server" Style="position: relative; left: 8px;" Text="<%#Bind('Tip') %>"></asp:Label>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Bonus" ItemStyle-Width="70">
                                                                        <ItemTemplate>
                                                                            <div id="divDays6" runat="server">
                                                                                <asp:Label ID="lblBonus" runat="server" Style="position: relative; left: 8px;" Text="<%#Bind('Bonus') %>"></asp:Label>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Penalty" ItemStyle-Width="70">
                                                                        <ItemTemplate>
                                                                            <div id="divDays7" runat="server">
                                                                                <asp:Label ID="lblAdvance" runat="server" Style="position: relative; left: 8px;"
                                                                                    Text="<%#Bind('Advance') %>"></asp:Label>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Advance" ItemStyle-Width="70">
                                                                        <ItemTemplate>
                                                                            <div id="divDays8" runat="server">
                                                                                <asp:Label ID="lblPenalty" runat="server" Style="position: relative; left: 8px;"
                                                                                    Text="<%#Bind('Penalty') %>"></asp:Label>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Ontime">
                                                                        <ItemTemplate>
                                                                            <div id="divDays9" runat="server">
                                                                                <asp:CheckBox ID="chkOnTime" runat="server" Checked="<%#Bind('ontime') %>" Enabled="false" />
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Late" ItemStyle-Width="70">
                                                                        <ItemTemplate>
                                                                            <div id="divDays10" runat="server">
                                                                                <asp:Label ID="lblLate" runat="server" Style="position: relative; left: 8px;" Text="<%#Bind('latehour') %>"></asp:Label>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                </Columns>
                                                            </asp:GridView>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </fieldset>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 29 Apr 2013, 04:39 AM
Hi,

Try the following.
aspx:
<telerik:RadGrid ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource"  AutoGenerateColumns="false" runat="server">
   <MasterTableView>
     <Columns>
      <telerik:GridBoundColumn DataField="EmployeeID"  UniqueName="EmployeeID"></telerik:GridBoundColumn>
       <telerik:GridTemplateColumn>
           <ItemTemplate>
               <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
           </ItemTemplate>
        </telerik:GridTemplateColumn>
  </MasterTableView>
</telerik:RadGrid>
c#
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        SqlConnection con1 = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
        SqlCommand cmd = new SqlCommand("SELECT top 10 * FROM [Orders]", con1);
        SqlDataAdapter ad = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        ad.Fill(ds);
       RadGrid1.DataSource = ds;
    }
Thanks,
Shinu
0
Swedha
Top achievements
Rank 1
answered on 05 Feb 2019, 12:33 PM

Hi ,

I am converting asp grid view to rad grid for my application. I have edit, delete functionality for the rows. Here is my row editing code 

protected void GridViewDocs_RowEditing(object sender, GridViewEditEventArgs e)
        {
            RegularExpressionValidatorVersion.Enabled = false;
            this.UpdateId = Convert.ToInt32(GridViewDocs.DataKeys[e.NewEditIndex].Value);

            int rowIndex = Convert.ToInt32(e.NewEditIndex);
            GridViewRow row = GridViewDocs.Rows[rowIndex];. . . 

I just need to take the updateid value and row values in rad grid .

Can you help me how to modify that in my radgrid editing functionality ?

. . 

0
Attila Antal
Telerik team
answered on 08 Feb 2019, 10:06 AM
Hi Swedha,

Please check out the following Documentation articles. They will help guide you through the process.

The Accessing Raw Field Data and Key Values will explain, how to access Field data or key values, which can serve as identifiers (or any other purpose) when needed. For inserting new records you can check out the Grid - Data Editing  section of the documentation. For instance, check out how the manual Insert operation is done:  Inserting Values Using InPlace and EditForms Modes and the update operation: Updating Values Using InPlace and EditForms Modes. Once you need to extract value, follow the instructions from the Extracting values article.

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
Aftab
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Swedha
Top achievements
Rank 1
Attila Antal
Telerik team
Share this question
or