private string getTableCont() { int count = 0, pagesize = 18, pages, pagescount, listbegin, minID; int liststep = 18; if (state.Equals(viewID) == false) { string delsql = "if exists(select * from dbo.sysobjects where name='temp') drop table temp"; string gensql = "select * into temp from " + getViewName().Replace("Part", "Full"); string altersql = "alter table temp add [ID] [int] IDENTITY(1,1) NOT NULL"; try { SqlDB.RunSql(delsql); SqlDB.RunSql(gensql); SqlDB.RunSql(altersql); } catch (Exception ex) { Response.Write("服务器忙或查询出错,请稍后再试!" + ex.Message.ToString()); return "Error!"; } } pages = Convert.ToInt32(strPageNo); string sqlCount, minIDSql; sqlCount = "select count(*) from temp"; minIDSql = "select min(ID) from temp"; // MyLog.WriteLog("count : " + sqlCount); try { count = Convert.ToInt32(SqlDB.RunSqlReturn(sqlCount)); } catch (FormatException) { count = 0; } try { minID = Convert.ToInt32(SqlDB.RunSqlReturn(minIDSql)); } catch (FormatException) { minID = 0; } pagescount = count % pagesize == 0 ? count / pagesize : count / pagesize + 1; if (pagescount < pages) { pages = pagescount;//如果分页变量大总页数,则将分页变量设计为总页数 } if (pages < 1) { pages = 1;//如果分页变量小于1,则将分页变量设为1 } listbegin = (pages - (int) Math.Ceiling((double) liststep / 2));//从第几页开始显示分页信息 if (listbegin < 1) { listbegin = 1; } int listend = pages + liststep/2;//分页信息显示到第几页 if (listend > pagescount) { listend = pagescount + 1; } //显示数据部分 int recordbegin = (pages - 1) * pagesize + minID;//起始记录 int recordend = 0; recordend = recordbegin + pagesize; //最后一页记录显示处理 if (pages == pagescount) { recordend = (int)(recordbegin + pagesize * (count % pagesize) * 0.1); } StringBuilder sgetstrf = new StringBuilder(); //获取字段 string getstrf = "select * from " + getViewName() + " where 1<>1"; DataTable dtgetstrf = new DataTable(); dtgetstrf = SqlDB.GetTable(getstrf); for (int i = 0; i < dtgetstrf.Columns.Count; i++) { sgetstrf.Append("[" + dtgetstrf.Columns[i].ColumnName.ToString() + "],"); } dtgetstrf.Dispose(); sgetstrf.Replace("县(市)名称", "县(旗)名称"); string sql = "select top " + pagesize + " " + sgetstrf.Remove(sgetstrf.Length - 1, 1) + " from temp where [ID]>=" + recordbegin + " order by [ID]"; //Response.Write(sql); MyLog.WriteLog(sql); DataTable dt = new DataTable(); dt = SqlDB.GetTable(sql); StringBuilder sb = new StringBuilder(); StringBuilder field = new StringBuilder(); //查出字段名 if (state.Equals(viewID) == false) { field.Append(getFields()); } // //sb.Append(sql + "<br/>"); sb.Append("<table class='datatable'>"); sb.Append("<caption>" + getViewName().Substring(0, getViewName().Length - 5).Replace('[', ' ') + "</caption>"); sb.Append("<tr class='tth'>"); //打印出字段 sb.Append("<td></td>"); for (int i = 1; i < dt.Columns.Count; i++) { sb.Append("<td>" + dt.Columns[i].ColumnName.ToString() + "</td>"); } sb.Append("</tr>"); ///打印出字段结束 for (int i = 0; i < dt.Rows.Count; i++) { sb.Append("<tr>"); sb.Append("<td><a href='aspx/" + viewID + ".aspx?id=" + dt.Rows[i][0].ToString() + "' target='_blank'>显示详细</a></td>"); for (int j = 1; j < dt.Columns.Count; j++) { sb.Append("<td>" + dt.Rows[i][j].ToString() + "</td>"); } sb.Append("</tr>"); } sb.Append("</table>"); if (pagescount > 1) { sb.Append("<br/><div id='fy'>"); if (pages > 1) { sb.Append("<a href=/"javascript:showTable('" + viewID + "'," + (pages - 1) + ");/">上一页</a> "); }//>显示上一页 for (int i = listbegin; i < listend; i++) { if (i != pages) {//如果i不等于当前页 sb.Append("<a href=/"javascript:showTable('" + viewID + "'," + i.ToString().Trim() + ");/">" + i.ToString().Trim() + " </a> "); // MyLog.WriteLog("<a href='javascript:;' οnclick=/"showTableS('" + viewID + ";" + i.ToString().Trim() + "')/">" + i.ToString().Trim() + " </a> "); } else { sb.Append(i.ToString().Trim() + " "); } } //<显示下一页 if (pages != pagescount) { sb.Append("<a href=/"javascript:showTable('" + viewID + "'," + (pages + 1) + ");/">下一页</a>"); }//>显示下一页 sb.Append("</div>"); } if (state.Equals(viewID) == false) { sb.Append(";"); sb.Append(field.ToString()); } //如果viewID不变那么就不用重新生成字段 state = viewID; return sb.ToString(); }