下一站天后
今朝的容颜老于昨晚
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
::
88 随笔 :: 0 文章 :: 54 评论 :: 0 引用
vs2008 repeater 的ItemDataBound事件
早前发布过repeater控件的使用,因为用repeater较少,或是仅用简单操作,对它使用相当不熟练,这次利用它很方便的解决了一个问题,而且是使用linq读取数据就记录一下。
绑定问题后面显示答案个数,不是拼语句,不太好做,平时对repeater又不熟,想到用itemDateBind
protected
void
repMore_ItemDataBound(
object
sender, RepeaterItemEventArgs e)
{
if
(e.Item.ItemType
==
ListItemType.AlternatingItem
||
e.Item.ItemType
==
ListItemType.Item)
{
int
qId
=
Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,
"
Question_ID
"
));
//
得到主键
int
aNum
=
Answer.GetAnswerNumByQId(qId);
((Label)e.Item.FindControl(
"
lblANum
"
)).Text
=
aNum.ToString();
}
}
Code
<
asp:Repeater
runat
="server"
ID
="repMore"
onitemdatabound
="repMore_ItemDataBound"
>
<
ItemTemplate
><
dd
><
a
href
="More.aspx?type=encodeUrl(<%#Eval("
Type")%
>
)">[
<%
#
Eval
(
"
Type
"
)
%>
]
</
a
>
<
a
href
="QADetail.aspx?qId=<%#Eval("
Question_ID")%
>
">
<%
#
Eval
(
"
Title
"
)
%>
(
<
asp:Label
ID
="lblANum"
runat
="server"
Text
="Label"
></
asp:Label
>
)
</
a
>
<%
#
Eval
(
"
CreateDate
"
,
"
{0:MM-dd HH:mm}
"
)
%>
</
dd
></
ItemTemplate
>
</
asp:Repeater
>
下面是绑定repeater
using
QsqLib.LinqSql;
using
QsqLib;
using
QsqLib.Manyou.QA;
using
QsqLib.Manyou;
using
System.Collections.Generic;
using
System.Text;
using
System.Linq.Dynamic;
Code
void
BindMore()
{
/*
<dt><b>待解决的问题</b> </dt>
<dd><a href="#">[艺术文化]</a> <a href="#">谁知道《盗墓笔记》完整版的网址链接 (1)</a> 08-12 14:56</dd>
*/
string
type
=
Utils.GetQueryString(
"
type
"
);
//
类别更多
string
state
=
Utils.GetQueryString(
"
state
"
);
//
问题状态更多
string
qTitle
=
Utils.GetQueryString(
"
t
"
);
//
按问题模糊查询
string
strWhere
=
""
;
if
(type
==
""
&&
state
!=
""
)
//
状态
{
strWhere
=
"
State=='
"
+
state
+
"
'
"
;
title
=
state
==
"
Y
"
?
"
新解决的问题
"
:
"
待解决的问题
"
;
}
else
if
(type
!=
""
&&
state
==
""
)
//
类型
{
strWhere
=
"
Type==\
""
+ type +
"
\
""
;
title
=
"
[
"
+
type
+
"
]下的问题
"
;
}
else
if
(type
==
""
&&
state
==
""
&&
qTitle
!=
""
)
{
//
strWhere = "Title like '%"+title+"%'";
strWhere
=
"
Title.Contains(\
""
+ qTitle +
"
\
"
)
"
;
title
=
"
搜索结果
"
;
}
else
{
Utils.MessageBox(
"
违规操作!
"
,
this
);
return
;
}
var q
=
Question.GetQuestionByWhere(strWhere).OrderBy(o
=>
o.OrderBy).ThenByDescending(o
=>
o.CreateDate);
AspNetPager1.RecordCount
=
q.Count();
repMore.DataSource
=
q.Skip((AspNetPager1.CurrentPageIndex
-
1
)
*
AspNetPager1.PageSize).Take(AspNetPager1.PageSize);
repMore.DataBind();
this
.labCountPage.Text
=
CountPage(AspNetPager1.RecordCount, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
}
跟多事件功能参看 http://www.cnblogs.com/VirtualMJ/archive/2007/03/09/669613.html
绿色通道:
好文要顶
关注我
收藏该文
与我联系
posted on 2009-09-07 14:56
孙雅玲
阅读(391)
评论(0)
编辑
收藏
注册用户登录后才能发表评论,请
登录
或
注册
,
返回博客园首页
。
首页
博问
闪存
新闻
园子
招聘
知识库
最新IT新闻
:
·
谷歌将出售Clearwire股份 不到收购价1/10
·
为什么Google比苹果更令微软恐惧?
·
思科拟2.71亿美元收购私有公司Lightwire
·
社交商务公司Bazaarvoice将于2月24日进行IPO
·
戴尔收购备份软件公司AppAssure
»
更多新闻...
最新知识库文章
:
·
领域模型管理与AOP
·
编程的艺术:漂亮的代码和漂亮的软件
·
GIT分支管理是一门艺术
·
编程:是一门艺术
·
编程是一门艺术吗?
»
更多知识库文章...
China-pub 2011秋季教材巡展
China-Pub 计算机绝版图书按需印刷服务
<
2009年9月
>
日
一
二
三
四
五
六
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
公告
昵称:
孙雅玲
园龄:
3年7个月
粉丝:
5
关注:
2
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
随笔分类
网站架构与性能优化(1)
(rss)
Ajax(2)
(rss)
c#(28)
(rss)
html(6)
(rss)
js(14)
(rss)
sql server(12)
(rss)
工具与控件(7)
(rss)
配置环境(8)
(rss)
语法(12)
(rss)
随笔档案
2011年8月 (1)
2011年7月 (1)
2010年7月 (1)
2009年10月 (1)
2009年9月 (2)
2009年6月 (5)
2009年5月 (1)
2009年4月 (6)
2009年3月 (4)
2009年2月 (9)
2009年1月 (3)
2008年12月 (5)
2008年11月 (8)
2008年10月 (8)
2008年9月 (21)
2008年8月 (12)
积分与排名
积分 - 31255
排名 - 3435
最新评论
阅读排行榜
评论排行榜
推荐排行榜