ASP.NET的GridView分页问题 [英] ASP.NET Gridview Paging Problem
本文介绍了ASP.NET的GridView分页问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个是在$ C $数据绑定C-背后使用存储过程的GridView。我处理了code中的寻呼事件为好,但每当我点击一个页码,我不断收到,而不是更多的行空的数据模板。有什么建议?
编辑:我重新绑定GV的数据源后,我改变了页面索引
。下面是我的code - 我有一个确定哪些数据源是一个下拉列表:
保护小组ddlProjectForm_SelectedIndexChanged(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手ddlProjectForm.SelectedIndexChanged
昏暗strProjectFormID作为字符串= Me.ddlProjectForm.SelectedValue
昏暗康恩作为新的SqlConnection(WebConfigurationManager.ConnectionStrings(康涅狄格州)。ConnectionString中)
DIM CMD作为新的SqlCommand()
昏暗的DA作为新的SqlDataAdapter
昏暗的DS作为新的数据集 如果strProjectFormID<> 选择然后
尝试
康涅狄格州使用
conn.Open() 用CMD
■连接=康恩
.CommandType = CommandType.StoredProcedure
.CommandText =sp_GetAllFormData
.Parameters.AddWithValue(@ projectFormID,strProjectFormID)
结束与 da.SelectCommand = CMD
da.Fill(DS) Me.gvAllSentData.DataSource = ds.Tables(0)
Me.gvAllSentData.DataBind()
Me.gvAllSentData.Visible = TRUE
使用完
赶上sqlEx作为的SQLException
昏暗newError作为新ErrorLogger(Me.Page.Title,sqlEx.Message,会议(用户名))
newError.LogError() Trace.Write(sqlEx.Message)
Me.lblBadFeedback.Visible = TRUE
Me.lblBadFeedback.Text =很抱歉。 - 发生了错误它已被记录,并将由站点管理员进行审查
抓住EX为例外
昏暗newError作为新ErrorLogger(Me.Page.Title,ex.Message,会议(用户名))
newError.LogError() Trace.Write(ex.Message)
Me.lblBadFeedback.Visible = TRUE
Me.lblBadFeedback.Text =很抱歉。 - 发生了错误它已被记录,并将由站点管理员进行审查
结束Try
其他
Me.gvAllSentData.DataSource =什么
Me.gvAllSentData.Visible = FALSE
万一结束小组保护小组gvAllSentData_PageIndexChanging(BYVAL发件人为对象,BYVAL E上System.Web.UI.WebControls.GridViewPageEventArgs)处理gvAllSentData.PageIndexChanging
Me.gvAllSentData.PageIndex = e.NewPageIndex
Me.gvAllSentData.DataBind()
结束小组
解决方案
正在重新绑定一个空的数据源。您code应改为:
保护小组gvAllSentData_PageIndexChanging(BYVAL发件人为对象,BYVAL E上System.Web.UI.WebControls.GridViewPageEventArgs)处理gvAllSentData.PageIndexChanging
Me.gvAllSentData.PageIndex = e.NewPageIndex
Me.gvAllSentData.DataSource = __The_Data_To_Bind__
Me.gvAllSentData.DataBind()
结束小组
I have a gridview that is databound in the code-behind using a stored procedure. I am handling the Paging event in the code as well, but whenever I click on a page number, I keep getting the empty data template instead of more rows. Any suggestions?
EDIT: I am re-binding the data source of the gv after I change the page index.
Here is my code - I have a dropdown list that determines what the data source is:
Protected Sub ddlProjectForm_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlProjectForm.SelectedIndexChanged
Dim strProjectFormID As String = Me.ddlProjectForm.SelectedValue
Dim conn As New SqlConnection(WebConfigurationManager.ConnectionStrings("Conn").ConnectionString)
Dim cmd As New SqlCommand()
Dim da As New SqlDataAdapter
Dim ds As New DataSet
If strProjectFormID <> "Select" Then
Try
Using conn
conn.Open()
With cmd
.Connection = conn
.CommandType = CommandType.StoredProcedure
.CommandText = "sp_GetAllFormData"
.Parameters.AddWithValue("@projectFormID", strProjectFormID)
End With
da.SelectCommand = cmd
da.Fill(ds)
Me.gvAllSentData.DataSource = ds.Tables(0)
Me.gvAllSentData.DataBind()
Me.gvAllSentData.Visible = True
End Using
Catch sqlEx As SqlException
Dim newError As New ErrorLogger(Me.Page.Title, sqlEx.Message, Session("UserName"))
newError.LogError()
Trace.Write(sqlEx.Message)
Me.lblBadFeedback.Visible = True
Me.lblBadFeedback.Text = "We're sorry - an error has occurred. It has been logged and will be reviewed by the site admin."
Catch ex As Exception
Dim newError As New ErrorLogger(Me.Page.Title, ex.Message, Session("UserName"))
newError.LogError()
Trace.Write(ex.Message)
Me.lblBadFeedback.Visible = True
Me.lblBadFeedback.Text = "We're sorry - an error has occurred. It has been logged and will be reviewed by the site admin."
End Try
Else
Me.gvAllSentData.DataSource = Nothing
Me.gvAllSentData.Visible = False
End If
End Sub
Protected Sub gvAllSentData_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvAllSentData.PageIndexChanging
Me.gvAllSentData.PageIndex = e.NewPageIndex
Me.gvAllSentData.DataBind()
End Sub
解决方案
You are rebinding an empty datasource. Your code should read:
Protected Sub gvAllSentData_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvAllSentData.PageIndexChanging
Me.gvAllSentData.PageIndex = e.NewPageIndex
Me.gvAllSentData.DataSource = __The_Data_To_Bind__
Me.gvAllSentData.DataBind()
End Sub
这篇关于ASP.NET的GridView分页问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文