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

Grid Bound column

1 Answer 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
raju
Top achievements
Rank 1
raju asked on 02 Jun 2010, 12:34 AM
Hi Guys,
               I am new be in Telerik . Here is the small issue of I am getting Student mark  from Data base so i have to find out student percentage.
Here is my code. I have to findout percentage.... please need help to figure it out. I wanted to do in code behind

<telerik:RadGrid ID="RadGrid1" runat="server">
            <MasterTableView TableLayout="Fixed">
                <Columns>
                    <telerik:GridBoundColumn DataField="Student_ID" SortExpression="StudentID" DataType="System.Int32" UniqueName="StudentID" HeaderText="StudentID" />
                    <telerik:GridBoundColumn DataField="Student_Name" SortExpression="Student_Name" DataType="System.String" UniqueName="Student_Name" HeaderText="StudentName" />
                    <telerik:GridBoundColumn DataField="Student_LastName" SortExpression="Student_LastName" DataType="System.String" UniqueName="Student_LastName" HeaderText="StudentLastName" />
                    <telerik:GridBoundColumn DataField="Student_Mark" SortExpression="Student_Mark" DataType="System.String" UniqueName="Student_Mark" HeaderText="StudentMark"/>
<telerik:GridBoundColumn  SortExpression="Student_Percentage" DataType="System.String" UniqueName="Student_Percentage" HeaderText="StudentLastName" />
<Columns>

<telerik:GridBoundColumn DataField="Student_LastName" SortExpression="Student_LastName" DataType="System.String" UniqueName="Student_LastName" HeaderText="StudentLastName" />

                        <FooterTemplate>
                            Template footer
                        </FooterTemplate>
                        <HeaderTemplate>
                            <table id="Table1" cellspacing="0" cellpadding="0" width="20" border="1" runat="server">
                                <tr>
                                    <td colspan="2" align="center">
                                        <b>School details</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 50%" align="center">
                                        <asp:LinkButton Width="140" ID="btnContName" Text="Contact name" ToolTip="Sort by ContactName"
                                            CommandName='Sort' CommandArgument='ContactName' runat="server" />
                                    </td>
                                    <td style="width: 50%" align="center">
                                        <asp:LinkButton Width="140" ID="btnContTitle" Text="Contact title" ToolTip="Sort by ContactTitle"
                                            CommandName='Sort' CommandArgument='ContactTitle' runat="server" />
                                    </td>
                                </tr>
                            </table>
                        </HeaderTemplate>
                        <ItemTemplate>
                            
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

Thanks,Raju!!!!!!!!!!

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Jun 2010, 06:39 AM
Hello Raju,

Since the DataType of the field "Student_Mark" is string, you have to convert it into integer to find out percentage. Then you can access the cell "Student_Percentage" using GridDataItem and assign the corresponding percentage value from code behind.

C#:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            string mark = item["Student_Mark"].Text; 
            Int32 mark1 = Convert.ToInt32(mark); 
            int percentage = (mark1 / 200)*100;    //use your equation to find out percentage 
            item["Student_Percentage"].Text = percentage.ToString(); 
        } 
   } 

Regards,
Shinu.


Tags
Grid
Asked by
raju
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or