Datagrid question

S

Sanjay

I am a newbie. On a button click, I use the following databind for a
datagrid that works perfectly. But after that, no matter which page
number I click at the bottom, I always get the first page. The same
happens with the column header clicks to sort, reverse-sort, etc. How
can I fix this? Thanks.

void btEntry_Click(object sender, EventArgs e) {

dataSrc.SelectCommand = "SELECT * FROM [visits] where
visitedPage like @anStr";

dataSrc.Parameters.Clear();

dataSrc.Parameters.Add("@anStr", srchBox.Text);

dataGrid.DataBind();

}
 
R

ranganh

Hi

Did you write the OnPageIndexChanged functionality

the place where you declare the datagrid, include the following attribute OnPageIndexChanged="dataGrid_PageIndexChanged" and then you have to write the following in your code behin

public void dataGrid_PageIndexChanged(object s, DataGridPageChangedEventArgs e) //Function for paging


dataGrid.CurrentPageIndex = e.NewPageIndex
BindData()
 
W

winenthu

Sorry, I didn't mention that it is an mxdatagrid and I am using
webmatrix. Usually this control does an auto paging, sorting, etc. Only
when I put the AutoDataBind off and then manually bind data, the paging
features are broken. The code that you gave does not fix this.

The problem is I don't know the whole picture of how this control works,
and any books that I have read fail to give the advanced usage. If I
have changed the data source with a new select statement and now the
mxdatagrid is using that data source, how to get it to do autopaging,
etc for the new data?

Thanks.
 
W

winenthu

I finally solved this problem by the following code modification (note
that this is mxdatagrid and not datagrid):

<code>
void Page_Load(Object sender, EventArgs E ) {
if (IsPostBack) {
dataGrid.AutoDataBind = true;
dataGrid.DataBind();
}
}

void btEntry_Click(object sender, EventArgs e) {
dataGrid.AutoDataBind = false;
dataSrc.SelectCommand = "SELECT * FROM [visits] where
visitedPage like @anStr";
dataSrc.Parameters.Clear();
dataSrc.Parameters.Add("@anStr", srchBox.Text);
dataGrid.DataBind();
}
</code>
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top