Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Databinding and PageIndexChanged() event

Reply
Thread Tools

Re: Databinding and PageIndexChanged() event

 
 
bruceb
Guest
Posts: n/a
 
      01-25-2005
I have had the same problem and believe that I have discovered the
exact reaason why the event does not fire.

It has to do with the way in which the datagrid columns are added. If
columns are added during the method in which you perform the
BindData(), then the PageIndexChanged event seems to get corrupted.

To correct the issue place all of the column code into a method that
you call from within the OnInit() method as follows:


override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
AddDataGridColumns();
base.OnInit(e);
}

Place all of the code for creating the columns the the
AddDataGridColumns method:

private void AddDataGridColumns()
{
// Add columns
HyperLinkColumn hlinkcol = new HyperLinkColumn();

hlinkcol.DataNavigateUrlField = "AssessorDetailId";
hlinkcol.DataNavigateUrlFormatString="Receipt.aspx ?function=Edit&id={0}";
hlinkcol.DataTextField="Equ_AcctKey";
hlinkcol.HeaderText = "Equ Account";
hlinkcol.Target="_blank";
grdResults.Columns.Add(hlinkcol);

BoundColumn dgc_wriAccount = new BoundColumn();
dgc_wriAccount.DataField = "Wri_acctKey";
dgc_wriAccount.HeaderText = "WRI Account";
dgc_wriAccount.ItemStyle.Width = new Unit(100);
grdResults.Columns.Add(dgc_wriAccount);
....
}

Then the event and the BindDate method should like like the following:

private void grdResults_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
grdResults.CurrentPageIndex = e.NewPageIndex;
BindData();
}

private void BindData()
{
ConnectionString =
ConfigurationSettings.AppSettings["ConnectionString"];

receipt = new TaxBillReceipt(ConnectionString);
receipt.LoadList(int.Parse(txtTaxYear.Text),
txtState.Text,
txtCadName.Text,
txtAssessor.Text,
txtCostCenter.Text,
txtWriKey.Text,
txtEquKey.Text);

grdResults.AutoGenerateColumns = false;
grdResults.DataSource = receipt.recDs.Tables[0];
grdResults.DataKeyField = "AssessorDetailId";

grdResults.DataBind();
}

This means that the bound columns are already added to the data grid
before any binding is attempted. This corrected my problem completely.

Bruce
www.gatewayhorizons.com


Jim Ross [MVP] wrote:
> I have observed this when viewstate is not turned on for the page or
> the grid.
>
> "Jeffrey H" <(E-Mail Removed)> wrote:
>
> >I have a DataGrid with paging, implemented in a very standard way.
> >
> >My DataGrid posts just fine with the first set of records, and with

page
> >numbers. But when I click a page number, the DataGrid does not

reappear.
> >
> >It turns out that the _PageIndexChanged() event is not firing.

What's
> >causing this problem?
> >

>
> Jim Ross
> MS MVP [VC/MFC]
>
> Remove "nospam" to send email, but please ask all questions in the

newsgroups, not via private mail

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page event sequence and Databinding question Savvoulidis Iordanis ASP .Net 2 09-25-2008 09:23 AM
Databinding expressions are only supported on objects that have a DataBinding event jobs ASP .Net 0 09-25-2007 11:54 PM
Confused about databinding and event order Larry Bud ASP .Net 1 01-02-2007 07:12 PM
Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all? Sergei Shelukhin ASP .Net 1 11-12-2006 01:43 PM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM



Advertisments