this is a different datagrid problem than the one listed a few threads below this one. but it is the same datagrid and i would kindly appreciate help on both problems.<BR><BR>this problem is that my datagrid does not seem to be paging properly. the grid gets filled fine at first for the first page, but then when i click on any of the page number links at the bottom of the first page, the grid disappears and all i have is the rest of the page&#039;s formatting without any results. this tells me that my script for handling the event is not working.<BR><BR>here is the top line of the datagrid&#039;s code in html. i am omitting the rest of the datagrid&#039;s html code here because it is not relevant:<BR>-----------------------------------------------------------------<BR>&#060;asp:DataGrid id="MyDataGrid" runat="server" BorderWidth="0" CellPadding="3" AllowPaging="true" AutoGenerateColumns="false" OnPageIndexChanged="Grid_Change"&#062;<BR>-----------------------------------------------------------------<BR>here is the Grid_Change sub that is called by the OnPageIndexChanged event:<BR>-----------------------------------------------------------------<BR>Sub Grid_Change(sender As Object, e As DataGridPageChangedEventArgs)<BR> &#039; Set CurrentPageIndex to the page the user clicked.<BR> MyDataGrid.CurrentPageIndex = e.NewPageIndex <BR><BR> &#039; Rebind the data.<BR> Dim strSQL As String = Session("sessionSQL")<BR> Response.Write(strSQL)<BR> MyDataGrid.DataSource = CreateDataSource(strSQL)<BR> MyDataGrid.DataBind()<BR>End Sub &#039;Grid_Change<BR>-----------------------------------------------------------------<BR>please note that the response.write DOES output a proper sql statement, so the failure is not because of an empty variable. also, along those lines, you will notice that the sub calls a function. the same function is also called by the page_load sub. this function works properly for the page_load sub, but is not working properly now. it takes the sql string as an argument. i have the sql string stored in a session object to persist it outside the subs that call it. here is the code for the function:<BR>-----------------------------------------------------------------<BR>Function CreateDataSource(strSQL As String) As ICollection<BR> Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))<BR> myConnection.Open()<BR><BR> Dim objSQLDataAdapter As SQLDataAdapter = New SqlDataAdapter()<BR> Dim objDataset As DataSet = New DataSet()<BR> Dim FAQs As DataTable = objDataset.Tables.Add("FAQs")<BR> Dim ResultID As DataColumn = objDataset.Tables("FAQs").Columns.Add("ResultID")< BR><BR> ResultID.DataType = System.Type.GetType("System.Int32")<BR> With ResultID<BR> .AutoIncrement = True<BR> .AutoIncrementSeed = 1<BR> .AutoIncrementStep = 1<BR> End With<BR><BR> Dim myCommand As SqlCommand = New SqlCommand(strSQL, myConnection) <BR> myCommand.CommandType = CommandType.Text <BR><BR> objSQLDataAdapter.SelectCommand = myCommand <BR> objSQLDataAdapter.Fill(objDataset, "FAQs") <BR><BR> MyDataGrid.DataSource = objDataset.Tables("FAQs") <BR> MyDataGrid.DataBind()<BR><BR> IF MyDataGrid.PageCount = 1 THEN<BR><BR> END IF<BR><BR> IF objDataset.Tables("FAQs").Rows.Count = 0 THEN<BR> LabelSearchResults.Text = "Your search was too narrow, and did not return any results. Try loosening your search parameters."<BR> LabelSearchResults.Visible = True<BR> TableSearchResults.Visible = True<BR> MyDataGrid.Visible = False<BR> ELSE<BR> Dim ResultCount As String = objDataset.Tables("FAQs").Rows.Count<BR> Dim strSearchResults As String = "&#060;hr&#062;Your search yielded the following "<BR> strSearchResults = strSearchResults + ResultCount<BR> strSearchResults = strSearchResults + " results:"<BR> TableSearchResults.Visible = True<BR> LabelSearchResults.Text = strSearchResults<BR> END IF<BR>End Function<BR>-----------------------------------------------------------------<BR>also, when the search results first load, it happens because the BindTableData sub calls the CreateDataSource function. therefore, the CreateDataSource function works properly when it is called from the BindTableData sub but does not work properly when it is called from the Grid_Change sub. the code for the BindTableData sub is as follows:<BR>-----------------------------------------------------------------<BR>Sub BindTableData(strSQL As String)<BR> IF strSQL &#060;&#062; "TooBroad" THEN<BR> CreateDataSource(strSQL)<BR><BR> Session("sessionSQL") = strSQL<BR><BR> ELSE<BR> LabelSearchResults.Text = "Your search was too broad, and returned too many results to list. Try narrowing your search parameters."<BR> LabelSearchResults.Visible = True<BR> TableSearchResults.Visible = True<BR> END IF<BR>End Sub<BR>-----------------------------------------------------------------<BR>since response.write has shown that both subs are including the same correct sql statement as the argument when calling the CreateDataSource function, there has to be some other cause of this problem. can anyone show me what it is? <BR>