Paging Problem In Datagrid With Dynamically Added Columns

R

racingcow

Hello,

I have a DataGrid on a page that is used to display results from
multiple types of searches. When a search type is selected, I
dynamically add columns to my DataGrid. Three of the columns in the
datagrid are template columns with custom ItemTemplates. I have also
implemented paging on the grid (just normal paging -- not custom). My
problem is that when the user clicks on the "next" button in the pager,
the page reloads without any data being rendered to the datagrid.

My code structure looks somthing like this...

private void Page_Load(object sender, System.EventArgs e)
{
//m_searchType is retrieved from query string here
<...>

//Dynamically load search fields
LoadSearchFields();

//Dynamically add the columns to the datagrid
//(This is based on a "search type" query string
// parameter that is passed in)
BuildSearchResultsTable();
}

private void BuildSearchResultsTable()
{
switch (m_searchType)
{
case SearchTypes.Claims:
BuildSearchResultsTableClaims();
break;

<...>
}
}

private void BuildSearchResultsTableClaims()
{
//Columns are dynamically added here
<...>
}

private void btnSearch_Click(object sender, System.EventArgs e)
{
//Get the search criteria the user entered
SearchCriteria[] searchCriteria = <...>

//Execute the search
DataSet results = ExecuteSearch(m_userToken, searchCriteria);

//Display the results to the user
dgSearchResults.DataSource = results;
dgSearchResults.DataBind();
}

private void dgSearchResults_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgSearchResults.CurrentPageIndex = e.NewPageIndex;
btnSearch_Click(null, System.EventArgs.Empty);
}

Does anyone know how I can make the paging work correctly?
Thanks,
David
 

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,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top