这样的分页如何实现
如果有5页就生成5个数字点击进入页,如果是3页就生成3个数字
------解决方案--------------------得到总页数n
string pg= " ";
for(int i = 1;i <=n;i++)
{
pg+= " <a href= 'Page.aspx?page= " + i.ToString() + " '> " + i.ToString() + " </a> ";
}
Literal1.Text=pg;
------解决方案--------------------这个只是一种参考方法
你也可以不用querystring,把page index放在隐藏域里面
用gridview的分页就很好啊
------解决方案--------------------已前写的一段ASP分页代码,希望对你启发!!
Dim myConnection As SqlConnection = cn
Dim ds As DataSet = New DataSet
Dim adapter As SqlDataAdapter = New SqlDataAdapter(Sql, myConnection)
If adapter.Fill(ds, "Orders ") Then '判断是否取到值
dgItemSub.DataSource = ds.Tables( "Orders ").DefaultView
dgItemSub.DataBind()
ShowStats()
'---------------------------- 合并相同网格 ----------------------------
Dim k As Integer
Dim i As Integer
Dim j As Integer
Dim intSpan As Integer
Dim NowSpan As Integer = 0
Dim strTemp As String
'取三列合并()
For k = 0 To 2
For i = 0 To dgItemSub.Items.Count - 1
intSpan = 1
'得到第一列(颜色)、第一行单元格中的内容。
strTemp = dgItemSub.Items(i).Cells(k).Text.Trim.ToString
'循环判断。判断第一列中,和第一行相同的内容。相同做记号,intspan加一
For j = i + 1 To dgItemSub.Items.Count - 1
Dim strTest As String = dgItemSub.Items(j).Cells(k).Text.Trim.ToString
If strTemp = strTest Then
intSpan += 1
'利用datagrid的rowspan属性。(设置控件中单元格跨越的行数为intspan)
dgItemSub.Items(i).Cells(k).RowSpan = intSpan
'把内容相同单元格隐藏
dgItemSub.Items(j).Cells(k).Visible = False
'把三列后的与第三列一样合并
If k = 2 Then
Dim l As Integer
For l = 3 To 4
dgItemSub.Items(i).Cells(l).RowSpan = intSpan
dgItemSub.Items(j).Cells(l).Visible = False
Next
End If
Else
Exit For
End If
Next
NowSpan += intSpan '修改后的可以节省循环次数.
i = NowSpan - 1
Next
NowSpan = 0 '从零开始重新循环
Next
------解决方案--------------------用分页控件 AspNetPager可以实现