这几天一些总结

如果要count的话,               

DataSet AllTopicDS = _dao.QueryDataSet("KnowledgeInteraction.Topic.List.Count");

AllTopicNum = AllTopicDS.Tables[0].Rows[0]["AllTopicCount"].ToString();

如果用Eval判断字段是否为空,如果为空,赋值的话,

<%#string.IsNullOrEmpty(Eval("ClickNum ").ToString()) ? "0" : Eval("ClickNum")%>

如果用Eval判断真假,

<%# (bool)Eval("isAnonymous")  ==true ? "匿名" :Eval("CreatorName")%>

如果不能用Eval的话,

<%#AllTopicNum %>可以用这种方法,后台则全局定义这个变量,protected stirng AllTopicNum {get;set;} 一般可以定义一些Visible、Enabled之类的东西

LinkButton的使用:

<asp:LinkButton runat="server" ID="TopicCategoryLinkBtn" CommandArgument='<%#Eval("CategoryID")%>'  OnClick="TopicCategoryLinkBtn_Click"><%#Eval("CategoryName") %>(<%#Eval("Num")%> )</asp:LinkButton>

CommandArgument可以自己定义,一般为ID之类的字段

后台写一个OnClick函数

string CategoryID = ((LinkButton)sender).CommandArgument;

这样的话就可以把这个CommandArgument拿出来了,然后再进行其他数据控件的绑定。

数据库方面查询

string SelectHotTopicSql = @"select Top 5 * from dbo.Topic  

         left join (select count(1) as ClickNum, topicid  from dbo.TopicClick group by topicid) as TopicClickCount   on dbo.Topic.topicid=TopicClickCount.topicid

left join (select count(1) as CommentNum ,TopicID from TopicComment group by TopicID) as CommentCount  on dbo.Topic.TopicID = CommentCount.TopicID

left join (select CategoryName,CategoryID from TopicCategory) as Category   on Category.CategoryID = Topic.CategoryID

            where Topic.CategoryID ='" + CategoryID + "' order by ClickNum DESC";   

select count(1) as CommentNum ,TopicID from TopicComment group by TopicID 这种语句就是select出每个TopicID出现的次数,以CommentNum进行显示

加上一个as CommentCount 之后呢,就可以虚拟的看成是一张表

用left join可以连接几张表

用Repeater控件或者Datalist控件时候,

如果要对一个button进行OnClick事件的编写,则可以这样做

Button bt = sender as Button;//首先监听到这个按钮所在的Item

DataListItem dlt = bt.Parent as DataListItem;//拿到这个Item

HiddenField CommentIDHiddenField = dlt.FindControl("CommentIDHiddenField") as HiddenField;//一般这个HiddenField都会用来存一些ID之类的字段

string TopicCommentID = CommentIDHiddenField.Value;//拿到该条回复的id

foreach (DataListItem item in CommentList.Items)

{

   item.FindControl("SetBestBtn").Visible = false;//按下去后所有最佳回复按钮设为不可见,可以使一些页面元素改变

}

触发刷新页面的语句

Response.Redirect(Request.Url.ToString());//刷新页面

posted on 2011-09-22 20:02  嘭嘭帮  阅读(198)  评论(1编辑  收藏  举报

导航