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
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
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:
You can try the following code snippet to get the rows count in a page.
CS:
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
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
Iron
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
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:
cs:
Thanks
Princy.
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
Iron
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
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
Iron
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
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