我试了一下,在DataBind()前加上一行
myDataGrid.DataSource = Session("main4")
就可以啦!你是怎么指定DataSource的?
myDataGrid.DataSource = Session("main4")
就可以啦!你是怎么指定DataSource的?
解决方案 »
- repeater控件问题?
- 请教高手了。。谢谢各位。
- asp.net下载功能
- ASP.NEt开发环境大家用的是什么啊?vs2008开发版本是build版本吗?我下载了一个.iso的文件,几百M,下载好后没有办法安装,请问哪里可以下可用的?
- @@@高分求 软件交付使用的标准文档@@@
- 为了解决问题还是多送分吧!
- 需C#+SQL2005程序员
- [紧急求助]内网Win Server2008部署站点,域名访问时在IE中Cookie丢失
- asp.net里能调用.net自动产生的代理类中的异步调用方法吗?请大虾指教
- TextBox能否做Enter响应事件,如何做?
- brinkster.com中怎样用ASP.NET?
- 3 行的代码都有错 ?KAO 什么破书呀,误人子弟 !
我就是这样指定datasource的,可是datagrid数据就是不刷新,始终是第一页的数据。
论坛里的帖子我早看了个遍,可就是搞不定,所以才来高分求解啊
谁救救我!!!!!
If not ispostback Then...End If
还是不行,难道就没人会吗?????????
mycommand.fill(main4,"基本表")这样每次按第二页的时候,都只显示0记录到设定的page记录,所以无论如何也只能显示第一页的数据修改为:
mycommand.fill(main4,数据起始地址,数据结束地址,"基本表")这样就可以了,至于什么是数据起始地址,结束地址可以看看有关的datalist分面例程,其中数据开始地址就是你的当前页,使用myDataGrid.CurrentPageIndex就可得到,另外数据结束地址就是你的pagesize,可以用myDataGrid.PageSize取得,具体做法可以参考一下我的留言簿,我的留言簿下载地址是:http://aspxcn.com
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.DataSource=CreateDataView();
DataGrid1.CurrentPageIndex=0;
DataGrid1.CurrentPageIndex=e.NewPageIndex;
DataGrid1.DataBind();
}
//CreateDataView()为建立视图的自定义方法
if not ispostback then
datasource=table1
end if
databind()
在sub btn_click()中
session("table1")=table1
datasource=session("table1")
databind()没错我的问题就是 这样解决的!
Select Case sender.commandargument
Case "top"
DataGrid1.CurrentPageIndex = 0
pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
TextBox2.Text = DataGrid1.CurrentPageIndex + 1
Case "next"
If ((DataGrid1.CurrentPageIndex < DataGrid1.PageCount) And (DataGrid1.CurrentPageIndex >= 0)) Then
If (DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1) Then
pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
Else
DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex + 1
pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
TextBox2.Text = DataGrid1.CurrentPageIndex + 1
End If
End If
Case "prev"
If (DataGrid1.CurrentPageIndex > 0) Then
DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex - 1
pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
TextBox2.Text = DataGrid1.CurrentPageIndex + 1
End If
Case "last"
DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1
pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
TextBox2.Text = DataGrid1.CurrentPageIndex + 1
Case "cometo"
If CInt(TextBox2.Text) >= DataGrid1.PageCount Then
DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1
pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
Else
If CInt(TextBox2.Text) <= 0 Then
DataGrid1.CurrentPageIndex = 0
pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
Else
DataGrid1.CurrentPageIndex = CInt(TextBox2.Text) - 1
pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
End If
End If End Select
DataGrid1.DataBind()
if (myDataGrid.CurrentPageIndex>=0 and myDataGrid.CurrentPageIndex < myDataGrid.PageCount) then
myDataGrid.CurrentPageIndex =e.NewPageIndex
《。。此处少了DATASOURCE。。》
myDataGrid.DataBind ()
还有,此时的DATABIND其实什么事也没做,如果你把 btn_click 事件中的指定DATAVIEW的代码贴过来,问题就解决了,可是,这样每次都要连数据库,效率又太低,就转到我上面的问题了,哎,我也正发愁呢,因为用SESSION并不是太好,大家也顺便帮我看看啊
在mydatagrid_PageIndexChanged事件的myDataGrid.DataBind()一句前面加上:
DataSet ds = (DataSet)session("main4")
myDataGrid.DataSource = ds.Tables("基本表")try it.