Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable Sorting and Paging callback

Status
Not open for further replies.

josie2007

Technical User
Apr 14, 2007
90
US
I set enablesorting and paging callback property of gridview to true and enable pagint to true.when I try to go to a different page my gridview just disappear on me. any clue? thanks
 
How and where is the code that populates the grid? We need to see some code in order to help
 
Have you rebound your grid on the paging event. My guess is that you haven't in which case the GridView can't know that it is to be repopulated.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
thanks for the reply.
Here is my code:

Imports System.Data
Imports System.Data.OracleClient
Imports System.Configuration.ConfigurationManager
Partial Class ItemPerLine
Inherits System.Web.UI.Page
Dim ContractId As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim tody As DateTime = Date.Today
lblTime.Text = tody
Dim ContractId As String = Request.QueryString("contid")

Dim connectionString As String = ConnectionStrings("ConnectionString").ConnectionString
Dim oOracleConn As OracleConnection = New OracleConnection(connectionString)
oOracleConn.Open()

Dim strStringBuilder As StringBuilder
strStringBuilder = New StringBuilder
With strStringBuilder

.Append(" SELECT DISTINCT G.CSECNUM ""Section Number"", E.IPLINENO ""Line Number""")
.Append(" , E.EIITEM ""Item Number"", (i.idescrl ||' '|| e.isupdes) ""Item Description"" , ")
.Append(" I.IUNITS ""Item Units"" ,sum(E.IQTY) ""Quantity"", P.CPROJNUM ""S.P. Number"",P.CONTID, ")
.Append(" decode(trim(P.PRROUTE),null, 'N/A', P.PRROUTE) ""Route Number"", ")
.Append(" INITCAP(p.clocat1||p.clocat2||'---'||P.CDESCR) ""loc"", P.CDESCR ""Job Description"",")
.Append(" FUNC_GET_UNIT_NAME(IUNITS) ""Unit Name"",")
.Append(" (select initcap(FUNC_GET_COUNTY_NAME(CCNTY1)) ")
.Append(" FROM proposal where contid=" & "'" & ContractId & "'" & ") ""County Name""")
.Append(" FROM ITEMLIST I,ESTITEM E,ESTCATG G,PROPPROJ X,PROPOSAL P ")
.Append(" WHERE(P.CONTID = X.CONTID And X.PCN = G.PCN And E.PCN = G.PCN And E.CN = G.CN) ")
.Append(" AND I.ITEM = E.EIITEM AND I.ISPECYR = P.CSPECYR AND E.IPLINENO <>' ' ")
.Append(" AND E.EIITEM <> '2550601/01000' AND E.EIITEM <> '2565601/00031' ")
.Append(" AND E.EIITEM <> '2565601/00032' AND E.EIITEM <> '2565601/00033' ")
.Append(" AND E.EIITEM <> '2402601/01000' ")
.Append(" AND P.contid=" & "'" & ContractId & "'")
.Append(" group by G.CSECNUM, I.IUNITS,p.clocat1,p.clocat2,e.isupdes, P.CONTID,P.CDESCR, P.CPROJNUM, I.IUNITS,P.PRROUTE, E.IPLINENO, E.EIITEM, I.IDESCRL ")
.Append(" order by 2")
End With

'CREATE A NEW COMMAND AND PASS THE SQL STATEMENT / CONNECTION OBJECT
Dim cmdItemDetail As OracleCommand = New OracleCommand()
cmdItemDetail.Connection = oOracleConn
cmdItemDetail.CommandType = CommandType.Text
cmdItemDetail.CommandText = strStringBuilder.ToString


Dim adItemDetail As New OracleDataAdapter(cmdItemDetail)
Dim dsItemDetail As New DataSet

'fill the dataset with the result of our query from the specified command
adItemDetail.Fill(dsItemDetail, "ItemDetails")

'Bind the DataSet to the GridView
gvItem.DataSource = dsItemDetail
gvItem.DataBind()

rtNumber.Text = dsItemDetail.Tables("ItemDetails").Rows(0).Item("Route Number").ToString()
spNumber.Text = dsItemDetail.Tables("ItemDetails").Rows(0).Item("S.P. Number").ToString()
cntId.Text = dsItemDetail.Tables("ItemDetails").Rows(0).Item("contid").ToString()
txtLocation.Text = dsItemDetail.Tables("ItemDetails").Rows(0).Item("loc").ToString()
lblCounty.Text = dsItemDetail.Tables("ItemDetails").Rows(0).Item("County Name").ToString()
lblTotal.Text = dsItemDetail.Tables("ItemDetails").Rows.Count.ToString

End Sub
Protected Sub gvItem_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvItem.PageIndexChanging
gvItem.PageIndex = e.NewPageIndex
BindData()
End Sub
 
Unfortunatly EnableSorting is not a magic checkbox... Like ca8msm said, you will have to capture the sort command, requery with the sort from the data and rebind the grid to the new data result.

You will probably want to get used to setting AutoGenerateColumns = False and start using the DataGrid's Property Builder to define the columns and sort commands.

Senior Software Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top