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
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()
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.