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
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