public string GetTVPager( string sFileName, ref int CurrentPage, int TotalNumber, int MaxPerPage, bool ShowTotal, bool ShowAllPages, string strUnit) { int TotalPage; string strUrl; if(TotalNumber==0||MaxPerPage==0) { return String.Empty; } if(TotalNumber%MaxPerPage==0) { TotalPage=TotalNumber/MaxPerPage; } else { TotalPage=TotalNumber/MaxPerPage+1; } if(CurrentPage>TotalPage) CurrentPage=TotalPage; StringBuilder sbPager=new StringBuilder(512); sbPager.Append("<table align='center'><tr><td>"); if(ShowTotal) sbPager.Append("共 <b>").Append(TotalNumber).Append("</b> ").Append(strUnit).Append(" "); strUrl=JoinChar(sFileName); if(CurrentPage<2) { sbPager.Append("首页 上一页 "); } else { sbPager.Append("<a href='").Append(strUrl).Append("page=1'>首页</a> ") .Append("<a href='").Append(strUrl).Append("page=").Append(CurrentPage-1).Append("'>上一页</a> "); } if(CurrentPage>=TotalPage) { sbPager.Append("下一页 尾页"); } else { sbPager.Append("<a href='").Append(strUrl).Append("page=").Append((CurrentPage+1)).Append("'>下一页</a> ") .Append("<a href='").Append(strUrl).Append("page=").Append(TotalPage).Append("'>尾页</a>"); } sbPager.Append(" 页次:<strong><font color=red>").Append(CurrentPage).Append("</font>/").Append(TotalPage).Append("</strong>页 "); sbPager.Append(" <b>").Append(MaxPerPage).Append("</b>").Append(strUnit).Append("/页"); if(ShowAllPages==true) { if(TotalPage>1) { sbPager.Append(" 转到第<input class='TextBox' type='text' name='page' size='3' maxlength='5' value='") .Append(CurrentPage).Append("' onKeyPress=/"if (event.keyCode==13) window.location='").Append(strUrl) .Append("page=").Append("'+this.value;/"'>页").Append(" <input type='button' class='TextBox' value='Go' οnclick=/"javascript: window.location='") .Append(strUrl).Append("page=").Append("'+page.value;/"'>"); } } sbPager.Append("</td></tr></table>"); return sbPager.ToString(); } public string JoinChar( string strUrl) { string url=String.Empty; if(strUrl==String.Empty) { return String.Empty; } if(strUrl.IndexOf("?")<strUrl.Length-1) { if(strUrl.IndexOf("?")>0) { if(strUrl.IndexOf("&")<strUrl.Length-1) { url=strUrl+"&"; } else { url=strUrl; } } else { url=strUrl+"?"; } } else { url=strUrl; } return url; } public string GetTVList( int BTypeID, int STypeID, string condition, ref int TotalNumber, ref int _pageIndex, int _rows) { string fChannelName=null; string TypeName=null; string fHits=null; string connStr=ConfigurationSettings.AppSettings["connStr"]; SqlConnection conn=new SqlConnection(connStr); string strSql="SELECT a.*,b.fTypeName AS TypeName FROM TV_Channel a INNER JOIN TV_Channel_Type b ON a.fTypeID = b.fTypeID INNER JOIN TV_Channel_Special c ON a.fSpecialID = c.fSpecialID"; if (BTypeID==1&&condition==String.Empty) { strSql+=" WHERE a.fTypeID = @STypeID"; } if(BTypeID==2) { strSql+=" where a.fSpecialID=@STypeID"; } if(condition!=String.Empty) { strSql+=" where "+condition; } strSql+=" ORDER BY a.fUpdateTime DESC"; SqlCommand comm=new SqlCommand(strSql,conn); comm.Parameters.Add("@StypeID",SqlDbType.Int); comm.Parameters["@StypeID"].Value=STypeID; StringBuilder sbTVList=new StringBuilder(1024); sbTVList.Append("<table width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#FFFFFF'>/n") .Append("<tr>/n<td align='center' bgcolor='#DCE4F4' style='padding-top: 4px;'>类别</td>/n") .Append("<td width='24%' height='23' align='center' bgcolor='#DCE4F4' style='padding-top: 4px;'>频道(发布者)</td>/n") .Append("<td height='23' align='center' bgcolor='#DCE4F4' style='padding-top: 4px;'>当前节目(点击查看本周节目表)</td>/n") .Append("<td width='5%' height='23' align='center' bgcolor='#DCE4F4' style='padding-top: 4px;'>播放</td>/n") .Append("<td width='6%' height='23' align='center' bgcolor='#DCE4F4' style='padding-top: 4px;'>点击</td>/n") .Append("<td width='11%' height='23' align='center' bgcolor='#DCE4F4' style='padding-top: 4px;'>推荐指数</td>/n") .Append(" </tr>/n<tr>/n<td colspan='6' align='center' bgcolor='#819BCD'><img src='images/spacer.gif' width='1' height='1'></td>/n") .Append("</tr>/n"); SqlDataAdapter da=new SqlDataAdapter(); da.SelectCommand=comm; DataSet ds=new DataSet(); conn.Open(); da.Fill(ds); conn.Close(); TotalNumber=ds.Tables[0].Rows.Count; int i=0; foreach(DataRow dr in ds.Tables[0].Rows) { if(TotalNumber%_rows==0) { if(_pageIndex>TotalNumber/_rows) _pageIndex=TotalNumber/_rows; } else { if(_pageIndex>TotalNumber/_rows) _pageIndex=TotalNumber/_rows+1; } if(_pageIndex>0) { if(i<(_pageIndex-1)*_rows) {++i; continue;}; if(i>_pageIndex*_rows-1) break; } TypeName=Convert.IsDBNull(dr["TypeName"])?String.Empty:dr["TypeName"].ToString(); fChannelName=Convert.IsDBNull(dr["fChannelName"])?String.Empty:dr["fChannelName"].ToString(); fHits=Convert.IsDBNull(dr["fHits"])?String.Empty:dr["fHits"].ToString(); if(i%2==0) { sbTVList.Append("<tr bgcolor='#ffffff'>/n"); } else { sbTVList.Append("<tr bgcolor='#DFF5FF'>/n"); } sbTVList.Append("<td height='22' align='center' class='number2'>/n").Append(TypeName).Append("</td>/n") .Append("<td height='22'>").Append(fChannelName).Append("</td>/n") .Append("<td> </td>/n") .Append("<td align='center'><a href='mdplay.asp?id=88021' target='_blank'><img src='images/bt.gif' alt='请安装相应软件后点击收看' width='14' height='15' border='0'></a></td>") .Append("<td align='center' class='number2'>").Append(fHits).Append("</td>/n") .Append("<td align='center'><img src='images/soutv_5star.gif' width='60' height='11'></td>") .Append("</tr>/n"); ++i; } sbTVList.Append("</table>/n"); return sbTVList.ToString(); }