datagrid as Composite control... PageIndexChanged event don't get Fired!! Pls Help

K

Kilic Beg

Hi

I am facing a problem...
I implemented DataGrid with other Controls as Composite Control.
The DataGrid works fine it gets display in my webform, but the Paging don't
work..
the PageIndexChanged event never gets fired...

I kinda find a solution..
If I call BindGrid() method in the CreateChildControls() method and later
also in the PageIndexChanged() method it works...
but I don't think that's right way..
Binding the DataGrid twice ???

can anybody give me any hints please..

source code:
==============
public class dgCControl : Control, INamingContainer
{

private DataGrid _DataGrid;

protected override void CreateChildControls()
{
createLayout();
if (!this.Page.IsPostBack)
{
//check first cookie and than
BindGrid();
}
else
{
BindGrid(); //it doesn't work without this why ?
}
}

private void createLayout()
{
_DataGrid = new DataGrid ();
_DataGrid.ID = "_DataGrid";
//....styles and bound columns
this._DataGrid.ItemDataBound += new
DataGridItemEventHandler(this.DataGrid_ItemDataBound);
this._DataGrid.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid_Page
IndexChanged);
}

private void BindGrid()
{
SqlConnection conn = new SqlConnection(DBConn);
SqlDataAdapter da = new SqlDataAdapter("Select * from Customers", conn);
try
{
DataSet ds = new DataSet();
da.Fill(ds);
_DataGrid.DataSource = ds.Tables[0];
_DataGrid.DataBind();
}
catch (Exception ex)
{
lbl_debug.Text = lbl_debug.Text + "Exeption in function[BindGrid] : " +
(ex.ToString()) + "<BR>";
}
finally
{
conn.Close();
conn.Dispose();
}
}

private void DataGrid_PageIndexChanged (object sender,
DataGridPageChangedEventArgs e)
{
_DataGrid.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
}
===========================

Any ideas???
I appreciate any help.

Thanks,

- Kilic
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top