Slow datagrid on postback

  • Thread starter OT Solutions, sales
  • Start date
O

OT Solutions, sales

Hello there,

I have a datagrid that has a select button (so the user can choose a
row) and also uses the datagrid sort.

If I have a smaller grid (say 150 rows) the response time of the sort
or select button (that just opens a popup with some information) is a
couple of seconds.

If I load in say 500 records into the datagrid (the load speed is
fine). As soon as I try and sort on a column, or select from the
grid, it takes about 20 seconds.

Does anyone know why this would be happening.

Any help would be appreciated,

Tom Olthoff

Here is a sample of the code:

<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px;
POSITION: absolute; TOP: 80px" runat="server"
CellPadding="2" CellSpacing="2" AllowPaging="True"
AllowSorting="True" Font-Names="Arial"
Font-Size="Smaller" PageSize="1000" AutoGenerateColumns="False"
OnSortCommand="SortResults"
OnPageIndexChanged="PageResults"
OnItemDataBound="DataGrid1_ItemDataBound"
OnSelectedIndexChanged="DataGrid1_SelectedIndexChanged">
<SelectedItemStyle BackColor="#8080FF"></SelectedItemStyle>
<HeaderStyle BackColor="Silver"></HeaderStyle>
<Columns>
<asp:ButtonColumn Visible="False" Text="Select"
CommandName="Select"></asp:ButtonColumn>
<asp:BoundColumn DataField="PositionCode"
SortExpression="PositionCode" HeaderText="Position
Code"></asp:BoundColumn>
<asp:BoundColumn DataField="UserName" SortExpression="UserName"
HeaderText="User Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Dept" SortExpression="Dept"
HeaderText="Department"></asp:BoundColumn>
<asp:BoundColumn DataField="Div" SortExpression="Div"
HeaderText="Division"></asp:BoundColumn>
<asp:BoundColumn DataField="ReplCycle" SortExpression="ReplCycle"
HeaderText="Replacement Cycle"></asp:BoundColumn>
<asp:BoundColumn DataField="ReplPolicy"
SortExpression="ReplPolicy" HeaderText="Replacement
Policy"></asp:BoundColumn>
</Columns>
<PagerStyle Visible="False" NextPageText="Next 5"
PrevPageText="Prev 5"></PagerStyle>
</asp:datagrid>


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then
BindData()
End If

End Sub

Sub BindData()
'1. Create a connection
Dim ConnectionString As String
Dim CommandText As String
Dim NewDV As DataView
Dim strSort As String
Dim strFilter As String

CommandText = "usp_GetPCs"

' Grab the connection from the global.asax file.
' (This is where the application variables are set)
ConnectionString = Application("sqlConnectionString")

Dim ds As New DataSet

ds = ViewState("DataSet")

If ds Is Nothing Then
Dim myConnection As New SqlConnection(ConnectionString)
Dim myCommand As New SqlDataAdapter(CommandText,
myConnection)
Dim ds2 As New DataSet
myCommand.Fill(ds2)
NewDV = ds2.Tables(0).DefaultView()
'Before DataBind - Add New Rows Here for Each Sub Heading
'We'll come back to this shortly!
strSort = "Dept, PositionCode"
ViewState("DataSet") = ds2
Else
strSort = ViewState("DataSort")
NewDV = ds.Tables(0).DefaultView()
ViewState("DataSet") = ds
End If

NewDV.Sort = strSort

DataGrid1.DataSource = NewDV
DataGrid1.DataBind()


ViewState("DataSort") = strSort

End Sub

Sub SortResults(ByVal sender As Object, ByVal e As
DataGridSortCommandEventArgs)
Dim strSort
Dim NewDS As DataSet
Dim NewDV As DataView

strSort = e.SortExpression

NewDS = ViewState("DataSet")
NewDV = NewDS.Tables(0).DefaultView
NewDV.Sort = strSort
ViewState("DataSort") = strSort
BindData()

End Sub


Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='Silver'")
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='White'")

Dim button As LinkButton = _
CType(e.Item.Cells(0).Controls(0), LinkButton)
e.Item.Attributes("onclick") = _
Page.GetPostBackClientHyperlink(button, "")

End If

End Sub



Sub EditRecord(ByVal PositionCode As Integer)


' Response.Redirect("AddActionType.aspx?ActionType_ID="
& ID)
' Response.Redirect("AddActionType.aspx?ActionType_ID="
& ID)

' Open the positionlist.aspx screen passing in the position
code
Response.Write("<script language='javascript'> {
window.open('PositionList.aspx?PositionCode=" & CStr(PositionCode) &
"'" & ",'PosWin','toolbar=no, height=690, width=990 ,top=20,left=20')
}</script>")
End Sub


Public Sub DataGrid1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DataGrid1.SelectedIndexChanged
' This is the event for the datagrid selection change (by
mouse click)
Dim ID As String
ID = DataGrid1.SelectedItem.Cells(1).Text
EditRecord(Val(ID))
End Sub
 
B

Brock Allen

The real question is what mechanism are you usiung for sorting. That's what
you should focus on or perhaps alternate mechanisms.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,979
Messages
2,570,183
Members
46,719
Latest member
login dogas.info

Latest Threads

Top