如何计算asp.net中转发器控件中最后一列的值 [英] how to count value of last column in repeater control in asp.net
本文介绍了如何计算asp.net中转发器控件中最后一列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看下面的图片我想要计算最后一列的值(cnt)我正在使用转发器控件。
https://lh5.googleusercontent.com/-M7W6AuZ1VG8/U_rQhXAxUOI/AAAAAAAABGg/wwt1Lv1TpfA/w426-h451/Untitled -1.jpg [ ^ ]
我想要的是什么?
Look at the below picture I want to count value of last column (cnt) I am using repeater control.
https://lh5.googleusercontent.com/-M7W6AuZ1VG8/U_rQhXAxUOI/AAAAAAAABGg/wwt1Lv1TpfA/w426-h451/Untitled-1.jpg[^]
what i want?
if (last column (cnt) is greater than 5> )
{
response.write ("6");
}
sql查询
sql query
SELECT id, category, ( SELECT COUNT(id) FROM entry_table WHERE category.id = entry_table.Cat_id) as cnt FROM category
转发器代码
Repeater code
<asp:Repeater ID="CloudTags" runat="server" OnItemDataBound="CloudTags_ItemDataBound">
<ItemTemplate>
<asp:HyperLink ID="HyperLink9" runat="server">
<%#DataBinder.Eval(Container,"DataItem.Category")%>
(<%#DataBinder.Eval(Container,"DataItem.cnt")%>)
</asp:HyperLink>
</ItemTemplate>
</asp:Repeater>
代码背后:
Code behind:
protected void CloudTags_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
}
推荐答案
您可以检查项目类型ItemDataBound
事件。然后试试这个:
You can check the item type inItemDataBound
Event. Then try this:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){
MyCount += Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "column_name"));
//MyCount is variable which is declared globaly
}
这篇关于如何计算asp.net中转发器控件中最后一列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文