I have my project 90% working with one Major hitch - ANY help is appreciated!
In a nutshell, it's a Server control which derives directly from an ASP DataGrid.
I then add a button column, some other meaningless stuff, and autogenerate the columns from a DataReader.
The problem is, sometimes the dynamically created column shows up on the grid - sometimes not.
I have a feeling that I'm battling ViewState - but I don't know how or why - or when for that matter.
Even the slightest change in the order in whaich I call things makes a world of difference.
Can anyone see a grotesque error here?
By the way - I have the whole thing working perfectly using a UserControl - I'm just trying to move each part one by one from the UserControl into a ServerControl so I can compile the dern thing and reuse it.
Also, I use the DataGrid's native DataSource and DataBind commands with a simple DataReader - the binding works fine.
public class GridSingleLinkButton : System.Web.UI.WebControls.DataGrid
<snip>
protected override
void OnInit(EventArgs e)
{
base.OnInit(e);
ID = "dgMain";
base.AutoGenerateColumns =
true;
DataKeyField = "MyDatabaseIDField";
}
protected override void CreateChildControls()
{
ButtonColumn BC = new ButtonColumn();
Columns.Add(BC);
BC.CommandName = "SelectItem";
BC.ButtonType = ButtonColumnType.LinkButton;
BC.DataTextField = "PrimaryColumn";
base.CreateChildControls();
// NOTE!! If I call base.CreateChildControls first - other wacky things happen.
}
<snip>
Other code not shown down here to hook up the button column click events. When the button column actually does show itself in the grid, this event code works every time - flawlessly. I can get the ID of the item clicked by using:
protected override
void OnItemCommand(DataGridCommandEventArgs e)
I am about to start making my typed datagrids, so I will be paying attention to this thread for some cautions... anyway, shouldn't you be implementing INamingContainer?
I'll try it - but I'm ASSuming that the DataGrid from which I inherit handles that for me - I'll check on the documentation but I believe that the Datagrid already implements INamingContainer.
I may be wrong, but I think you have to implement it in any derived class too.. I have had viewstate problems that just went away after implementing INamingContainer on a derived class.
None
0 Points
84 Posts
Control derived from DataGrid = Problems
May 27, 2005 04:13 PM|BillyWilly|LINK
I have my project 90% working with one Major hitch - ANY help is appreciated!
In a nutshell, it's a Server control which derives directly from an ASP DataGrid.
I then add a button column, some other meaningless stuff, and autogenerate the columns from a DataReader.
The problem is, sometimes the dynamically created column shows up on the grid - sometimes not.
I have a feeling that I'm battling ViewState - but I don't know how or why - or when for that matter.
Even the slightest change in the order in whaich I call things makes a world of difference.
Can anyone see a grotesque error here?
By the way - I have the whole thing working perfectly using a UserControl - I'm just trying to move each part one by one from the UserControl into a ServerControl so I can compile the dern thing and reuse it.
Also, I use the DataGrid's native DataSource and DataBind commands with a simple DataReader - the binding works fine.
Code below:
[ToolboxData("<{0}:GridSingleLinkButton runat=serverX></{0}:GridSingleLinkButton>")]
public class GridSingleLinkButton : System.Web.UI.WebControls.DataGrid<snip>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);ID = "dgMain";
base.AutoGenerateColumns = true;DataKeyField = "MyDatabaseIDField";
}
protected override void CreateChildControls(){
ButtonColumn BC = new ButtonColumn();
Columns.Add(BC);
BC.CommandName = "SelectItem";
BC.ButtonType = ButtonColumnType.LinkButton;
BC.DataTextField = "PrimaryColumn";
base.CreateChildControls();
// NOTE!! If I call base.CreateChildControls first - other wacky things happen.
}
Other code not shown down here to hook up the button column click events. When the button column actually does show itself in the grid, this event code works every time - flawlessly. I can get the ID of the item clicked by using:
protected override void OnItemCommand(DataGridCommandEventArgs e)
{
if (e.CommandName == "SelectItem")DoSomething(DataKeys[e.Item.ItemIndex].ToString());
base.OnItemCommand(e);}
Member
230 Points
440 Posts
ASPInsiders
Re: Control derived from DataGrid = Problems
May 27, 2005 07:55 PM|subdigital|LINK
http://www.flux88.com
ASP.NET MVP
Certified ScrumMaster
ASPInsider
MCSD
None
0 Points
84 Posts
Re: Control derived from DataGrid = Problems
May 31, 2005 08:26 AM|BillyWilly|LINK
I'll try it - but I'm ASSuming that the DataGrid from which I inherit handles that for me - I'll check on the documentation but I believe that the Datagrid already implements INamingContainer.
Any more input will be appreciated.
- B
Member
230 Points
440 Posts
ASPInsiders
Re: Control derived from DataGrid = Problems
May 31, 2005 03:34 PM|subdigital|LINK
I may be wrong, but I think you have to implement it in any derived class too.. I have had viewstate problems that just went away after implementing INamingContainer on a derived class.
http://www.flux88.com
ASP.NET MVP
Certified ScrumMaster
ASPInsider
MCSD