Repost: Cannot create an instance of the abstract class datagridColumn

A

Andrew

I am trying to set the column information - which ones I want displayed and
how with the web grid control. The interface has some big differences when
compared to the winform.

Is this possible without having the dataset match ? I think yes... but ...
here's how I approached it: ( create new DataGridColumns, add properties and
then add each to the data grid. BUT I get an error when I try this:

C:\Inetpub\wwwroot\logvue\WebLogMgr.cs(192): Cannot create an instance of
the abstract class or interface 'System.Web.UI.WebControls.DataGridColumn'
if I dedclare it like without the new, then its says dgCol is unassigned and
wont complile. So what should I do ??? Thanks

for (int i =0;i< numCols;i++)
{ System.Web.UI.WebControls.DataGridColumn dgCol = new
System.Web.UI.WebControls.DataGridColumn();
dgCol.ItemStyle.Width=Convert.ToInt16(tabStyles.table[tabIndex].columns.width);
dgCol.HeaderText=tabStyles.table[tabIndex].columns.headertext;;
gridTX.Columns.Add(dgCol);
}
 
S

Steven Cheng[MSFT]

Hi Andrew,

From the code snipet and error message you provided, it seems that you get
the "Cannot create an instance of
the abstract class or interface 'System.Web.UI.WebControls.DataGridColumn"
error when you trying to instantial the
DataGridColumn class's instances and add them into the WebForm DataGrid's
columns collection , yes?

I think this problem is quite apparently since the
System.Web.UI.WebControls.DataGridColumn class is a Abstract class which
can't be directly instanced.

#DataGridColumn Class
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiwebcontro
lsdatagridcolumnclasstopic.asp?frame=true


And in fact we should use those buildin dervied class( derived from the
DataGridColumn class) in the System.Web.UI.WebControls. The following are
the list of those derived column classes:

System.Web.UI.WebControls.BoundColumn
System.Web.UI.WebControls.ButtonColumn
System.Web.UI.WebControls.EditCommandColumn
System.Web.UI.WebControls.HyperLinkColumn
System.Web.UI.WebControls.TemplateColumn

You can have a view at the System.Web.UI.WebControls namespace for a
detailed reference:

#System.Web.UI.WebControls Namespace
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIWebContro
ls.asp?frame=true

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
G

Guest

Thanks - I had to track down a sample of how these fit together :
( see 'what I needed ' and link )
http://dotnetjunkies.com/WebLog/ewise/archive/2004/06/23/17363.aspx

so I ended up with this:

for (int i =0;i< numCols;i++)
{ System.Web.UI.WebControls.DataGridColumn dgCol; // what I needed
System.Web.UI.WebControls.BoundColumn bCol = new System.Web.UI.WebControls.BoundColumn(); // what I needed
dgCol=bCol; // what I needed
dgCol.ItemStyle.Width=Convert.ToInt16(tabStyles.table[tabIndex].columns.width);
dgCol.HeaderText=tabStyles.table[tabIndex].columns.headertext;;
gridTX.Columns.Add(dgCol);
}
 

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

Top