Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > dynamic column/fields

Reply
Thread Tools

dynamic column/fields

 
 
=?Utf-8?B?RVI=?=
Guest
Posts: n/a
 
      01-07-2006
Hi,

I would like to create a datagrid or free entry form with dynamic columns
based on the user selection, do you have any ideas or samples?

Any help would be appreciated!

ER
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-07-2006
The datagrid server control provides a property named AutoGenerateColumns
that would allow the grid to display any number of columns that are on the
datatable.
http://msdn2.microsoft.com/en-us/lib...tecolumns.aspx

You can make the datagrid editable by adding an EditCommandColumn
http://msdn2.microsoft.com/en-us/lib...andcolumn.aspx

Another alternative is to turn the AutoGenerateColumns to false and then
compose the columns programmatically during databinding like this:
private void dgItems_DataBinding(object sender, System.EventArgs e)
{
DataTable dt = (DataTable)dgItems.DataSource;
for( int c=1; c<dt.Columns.Count; c++ )
{
BoundColumn bc = new BoundColumn();
bc.DataField = dt.Columns[c].ColumnName;
bc.HeaderText = dt.Columns[c].ColumnName;
dgItems.Columns.Add( bc );
}
}

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"ER" wrote:

> Hi,
>
> I would like to create a datagrid or free entry form with dynamic columns
> based on the user selection, do you have any ideas or samples?
>
> Any help would be appreciated!
>
> ER

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RVI=?=
Guest
Posts: n/a
 
      01-09-2006
Thanks Phillip. For the second solution, would that affect the performance if
the datagrid has significant data to display?

Thanks,
ER

"Phillip Williams" wrote:

> The datagrid server control provides a property named AutoGenerateColumns
> that would allow the grid to display any number of columns that are on the
> datatable.
> http://msdn2.microsoft.com/en-us/lib...tecolumns.aspx
>
> You can make the datagrid editable by adding an EditCommandColumn
> http://msdn2.microsoft.com/en-us/lib...andcolumn.aspx
>
> Another alternative is to turn the AutoGenerateColumns to false and then
> compose the columns programmatically during databinding like this:
> private void dgItems_DataBinding(object sender, System.EventArgs e)
> {
> DataTable dt = (DataTable)dgItems.DataSource;
> for( int c=1; c<dt.Columns.Count; c++ )
> {
> BoundColumn bc = new BoundColumn();
> bc.DataField = dt.Columns[c].ColumnName;
> bc.HeaderText = dt.Columns[c].ColumnName;
> dgItems.Columns.Add( bc );
> }
> }
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "ER" wrote:
>
> > Hi,
> >
> > I would like to create a datagrid or free entry form with dynamic columns
> > based on the user selection, do you have any ideas or samples?
> >
> > Any help would be appreciated!
> >
> > ER

 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-09-2006
I think that the performance would be the same.

If the only requirement in building the datagrid were to display all columns
without exception, such as the sample code below, then I prefer using the
declarative syntax (the first solution) because it makes the code more
readable and easily maintainable (one can change it without recompiling the
application).

If, on the other hand, one has to use different conditions for columns that
may or may not be provided in the data or if one has to hide particular
columns if they happen to exist in the data then the second approach would
work better.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"ER" wrote:

> Thanks Phillip. For the second solution, would that affect the performance if
> the datagrid has significant data to display?
>
> Thanks,
> ER
>
> "Phillip Williams" wrote:
>
> > The datagrid server control provides a property named AutoGenerateColumns
> > that would allow the grid to display any number of columns that are on the
> > datatable.
> > http://msdn2.microsoft.com/en-us/lib...tecolumns.aspx
> >
> > You can make the datagrid editable by adding an EditCommandColumn
> > http://msdn2.microsoft.com/en-us/lib...andcolumn.aspx
> >
> > Another alternative is to turn the AutoGenerateColumns to false and then
> > compose the columns programmatically during databinding like this:
> > private void dgItems_DataBinding(object sender, System.EventArgs e)
> > {
> > DataTable dt = (DataTable)dgItems.DataSource;
> > for( int c=1; c<dt.Columns.Count; c++ )
> > {
> > BoundColumn bc = new BoundColumn();
> > bc.DataField = dt.Columns[c].ColumnName;
> > bc.HeaderText = dt.Columns[c].ColumnName;
> > dgItems.Columns.Add( bc );
> > }
> > }
> >
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "ER" wrote:
> >
> > > Hi,
> > >
> > > I would like to create a datagrid or free entry form with dynamic columns
> > > based on the user selection, do you have any ideas or samples?
> > >
> > > Any help would be appreciated!
> > >
> > > ER

 
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
Dynamic Variables? OR Dynamic Controls =?Utf-8?B?VGVyb3M=?= ASP .Net 1 08-10-2004 01:13 PM
Dynamic control on aspx page, dynamic location Chris Thunell ASP .Net 3 07-21-2004 04:52 PM
VPN between 2 Cisco routers (1 static, 1 dynamic) with access from stat --> dynamic over ISDN Hans-Peter Walter Cisco 3 01-21-2004 02:12 PM
Does Pix or cisco router support dynamic-to-dynamic IPSec VPN? c Cisco 2 01-13-2004 01:53 AM
Re: Dynamic Table with Dynamic LinkButtons Rick Glos ASP .Net 0 07-08-2003 01:09 PM



Advertisments