进来看一看,分数轻松拿
DBOp dbop = new DBOp(Request.PhysicalApplicationPath);
int a = dbop.OpenDataBase();
if (a == 1)
{
OleDbDataAdapter da = new OleDbDataAdapter( "select * from Main_pricute ", dbop.DataBaseConn);
DataSet ds = new DataSet();
da.Fill(ds);
tablestr = " <table width=75% border=0 cellspacing=1 cellpadding=1> <tr> ";
for(int i =1;i <=ds.Tables[0].Rows.Count;i++)
{
if (ds.Tables[0].Rows[i - 1] != null)
{
//if (i <= 5)
//{
tablestr += " <td> <img src= '../../ " + ds.Tables[0].Rows[i - 1].ItemArray[7] + " ' width=100 height=100 border=0/> <br> " + ds.Tables[0].Rows[i - 1].ItemArray[1] + " </td> ";
//}
//if (i > 5 && i < ds.Tables[0].Rows.Count + 1)
//{
// tablestr += " <td> <a href=Main.aspx?id= " + Session[ "number "] + "> <img src= ' " + ds.Tables[0].Rows[i - 1].ItemArray[7] + " ' width=100 height=100 border=0/> </a> ";
//}
if (i % 6 == 0)
{
tablestr += " </tr> <tr> ";
}
}
}
tablestr += " </tr> <tr> <a href= List.aspx > 返回图片列表 </a> </tr> </table> ";
}
this.Literal1.Text = tablestr;
}
像这样,我在后天动态生成了一个图片表格,请问我怎么控制它的分页
[解决办法]
图片多么?
不多就一次输出到html里面,用隐藏层的方式来分
如果再多,那可能就要加分页处理
用sql语句分或是直接用控件提供的分页处理
[解决办法]
用这个sql语句
select top " + PAGESIZE.ToString() + " * from Main_pricute where id not in(select top " + ((pageIndex - 1) * PAGESIZE).ToString() + " id from Main_pricute
PAGESIZE是页的大小,pageIndex是页码,id是主键
注意如果用access的话,第一页不能用这个sql语句,直接用
select top " + PAGESIZE.ToString() + " * from Main_pricute
就可以
参数怎么处理自己看着办吧
[解决办法]
3列5行的方式可以用datalist控件,可以指定横向还是竖向排列,每列有几行,然后配合上面的sql语句一样使用。直接用数据绑定,比你这样自己直接生成html要简单
[解决办法]
代码有点乱,看的烦,^_^,帮顶
(后天才生成表格,今天就问问题了^_^)
[解决办法]
我在数据库里存的只是一个图片的路径,而且我要显示3列5行的表格,但绑定的是同一个字段,这样用datagrid也可以吗
__________________________________________________________
比如,你的表名叫tb,你要显示的字段是temp,现在要用同一字段显示一个3列5行的表个,具体做法是:
1、sql语句:select top 5 temp, temp, temp from tb
2、 <asp:DataGrid ID=grid runat=server > </asp:DataGrid>
3、将查询结果直接绑定给grid即可。
[解决办法]
比如,你的表名叫tb,你要显示的字段是temp,现在要用同一字段显示一个3列5行的表个,具体做法是:
1、sql语句:select top 5 temp, temp, temp from tb
2、 <asp:DataGrid ID=grid runat=server > </asp:DataGrid>
3、将查询结果直接绑定给grid即可。
[解决办法]
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
CreateLabel(CreateTable());
}
}
private DataTable CreateTable()
{
DataTable dt=new DataTable( "cart ");
DataColumn dc1=new DataColumn( "prizename ",Type.GetType( "System.String "));
DataColumn dc2=new DataColumn( "point ",Type.GetType( "System.Int16 "));
DataColumn dc3=new DataColumn( "number ",Type.GetType( "System.Int16 "));
DataColumn dc4=new DataColumn( "totalpoint ",Type.GetType( "System.Int64 "));
DataColumn dc5=new DataColumn( "prizeid ",Type.GetType( "System.String "));
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
dt.Columns.Add(dc5);
for(int i=0;i <10;i++)
{
DataRow dr=dt.NewRow();
dr[ "prizename "]= "ÍÞÍÞ ";
dr[ "point "]=10;
dr[ "number "]=1;
dr[ "totalpoint "]=10;
dr[ "prizeid "]= "001 ";
dt.Rows.Add(dr);
}
return dt;
}
private void CreateLabel(DataTable dt)
{
StringBuilder sb = new StringBuilder();
sb.Append( " <TABLE id= 'Table1 ' style= 'Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 8px ' cellSpacing= '1 ' cellPadding= '1 ' width= '300 ' border= '1 '> ");
for(int i = 0;i < dt.Rows.Count ; i++)
{
sb.Append( " <tr> ");
for(int j = 0 ;j < dt.Columns.Count; j ++)
{
sb.Append( " <td> ");
sb.Append(dt.Rows[i][j].ToString());
sb.Append( " </td> ");
}
sb.Append( " </tr> ");
}
sb.Append( " </table> ");
this.Response.Write(sb);
}
[解决办法]
1、sql语句:select top 5 temp, temp, temp from tb
2、 <asp:DataGrid ID=grid runat=server > </asp:DataGrid>
3、将查询结果直接绑定给grid即可
[解决办法]
.aspx页面
<tr height= "25 " valign= "bottom ">
<td colspan= "6 ">
<asp:label id= "Message " runat= "server " Font-Size= "11 "> </asp:label>
<asp:button id= "btnFirstPage " runat= "server " Text= "第一页 " ToolTip= "查看第一页数据 " CommandName= "第一页 "Width= "60 "> </asp:button>
<asp:button id= "btnPreviousPage " runat= "server " Text= "上一页 " ToolTip= "查看上一页数据 " CommandName= "上一页 "Width= "60 "> </asp:button>
<asp:button id= "btnNextPage " runat= "server " Text= "下一页 " ToolTip= "查看下一页数据 " CommandName= "下一页 " Width= "60 "> </asp:button>
<asp:button id= "btnLastPage " runat= "server " Text= "最后一页 " ToolTip= "查看最后一页数 据 " CommandName= "最后一页 "Width= "60 "> </asp:button>
</td>
</tr>
.cs页面
private void Page_Load(object sender, System.EventArgs e)
{
this.btnFirstPage.Click += new System.EventHandler(this.NavigateToPage);
this.btnPreviousPage.Click += new System.EventHandler(this.NavigateToPage);
this.btnNextPage.Click += new System.EventHandler(this.NavigateToPage);
this.btnLastPage.Click += new System.EventHandler(this.NavigateToPage);
if(!IsPostBack)
{
}
}
private void NavigateToPage(object sender, System.EventArgs e)
{
string PageInfo = ((Button)sender).CommandName;
switch (PageInfo)
{
case "第一页 ":
DataGridFatherModel.CurrentPageIndex = 0;
break;
case "上一页 ":
if (DataGridFatherModel.CurrentPageIndex > 0)
DataGridFatherModel.CurrentPageIndex -= 1;
break;
case "下一页 ":
if (DataGridFatherModel.CurrentPageIndex < (DataGridFatherModel.PageCount - 1))DataGridFatherModel.CurrentPageIndex += 1;
break;
case "最后一页 ":
DataGridFatherModel.CurrentPageIndex = (DataGridFatherModel.PageCount - 1);
break;
}
// 重新绑定至数据来源
BindGridToSource();
}