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

How to change all value on a column

6 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RRE
Top achievements
Rank 2
RRE asked on 12 Oct 2008, 04:33 PM
Hi,
I'm new and I need a littel help. :)

I have a gird attached to query.
At _ItemDataBound event I arrive to know the big Total of a field.
I need to update a colum to % of  big Total.

I arrive to do on _ItemDataBound event:

If (TypeOf e.Item Is GridFooterItem) Then
    [...]
   Dim dataitem As GridDataItem = CType(e.Item.OwnerTableView.ParentItem, GridDataItem)
   Dim item As GridDataItem   

   For x = 0 To ? 'where I read hou many row I have on table?

now I need to refer to x value on cell and change it but I'm not able!

someone can help me

Tanks

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Oct 2008, 04:27 AM
Hi Renato,

Try the following code snippet to get the enitre row count.

CS:
protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e) 
    { 
         if (e.EventInfo is GridInitializePagerItem) 
         { 
           int allRowsCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount; 
         } 
    } 

You can try the following code snippet to get the rows count in a page.

CS:
int rowCount = RadGrid1.MasterTableView.Items.Count; 

You can also refer the following help article to get details on setting totals in Grid footer.
http://www.telerik.com/help/aspnet-ajax/grdtotalsingridfooters.html

Thanks
Shinu
0
RRE
Top achievements
Rank 2
answered on 13 Oct 2008, 08:36 AM
Dear Shinu,

thanks for fast replay.
The first problem is ok.

But look at this example.

         Qantity   %Quantity
          70                 ?
          30                 ?
tot    100

where

%Quantity = quantity*100/tot

so after I calculated the total as describe in http://www.telerik.com/help/aspnet-ajax/grdtotalsingridfooters.html I have to update the all the %Quantity fields in radgrid.

I'm not able to refer to row data value on columns.

thanks
0
Princy
Top achievements
Rank 2
answered on 13 Oct 2008, 11:15 AM
Hello Renato,

Try out the code snippet given below to make calculations in a given column. Also modify the code according to your requirements.
aspx:
 <telerik:GridBoundColumn DataField="Quantity" UniqueName="Quantity" HeaderText="Quantity"></telerik:GridBoundColumn> 
          
<telerik:GridTemplateColumn UniqueName="Template"
 <ItemTemplate> 
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>               
 </ItemTemplate> 
</telerik:GridTemplateColumn> 

cs:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem dataItem in RadGrid1.Items) 
        { 
            Label lbl = (Label)dataItem.FindControl("Label1"); 
          // to access the row value for Quantity column
            int value1 = Convert.ToInt16(dataItem["Quantity"].Text); 
            int value2 = (value1 * 100) / total; 
            lbl.Text = Convert.ToString(value2); 
        } 
    } 

Thanks
Princy.
0
Princy
Top achievements
Rank 2
answered on 13 Oct 2008, 11:16 AM
 
0
RRE
Top achievements
Rank 2
answered on 13 Oct 2008, 03:03 PM
Dear Princy,

thanks for replay.

I translated into VB:

Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
        Dim dataItem As GridDataItem
        Dim lbl As Label
        Dim value1, value2 As Integer

        For Each dataItem In RadGrid1.Items

            lbl = CType(dataItem.FindControl("PercTotal"),Label)

            'to access the row value for Quantity column
            value1 = Convert.ToInt16(dataItem("Quantity").Text)
            value2 = (value1 * 100) / total
            lbl.Text = Convert.ToString(value2)
        Next
end sub

I have a problem:
            lbl = dataItem.FindControl("PercTotal")

return Nothing.

I looked at my asp source (iI simply droped on page my radgrid control) and I noted that is:

<radG:GridBoundColumn HeaderText="% PercTotal" UniqueName="PercTotal">
         <ItemStyle HorizontalAlign="Right" />
</radG:GridBoundColumn>

I'm not able to insert the 'ID' identifier for FindControl.

Can you help me?

Thanks




0
RRE
Top achievements
Rank 2
answered on 13 Oct 2008, 07:54 PM
I'm sorry, the answer is very simple!

        Dim dataItem As GridDataItem
        Dim value1, value2 As Integer

        For Each dataItem In RadGrid1.Items
            'to access the row value for Quantity column
            value1 = Convert.ToInt16(dataItem("Quantity").Text)
            dataItem("Perc").Text = (value1 * 100) / total
        Next

Tags
Grid
Asked by
RRE
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
RRE
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or