Custom Columns in GridView
Custom Columns in GridView
am 24.01.2008 05:20:35 von andytidy
After going through some newbie examples I've created a DAL and BLL
for my project. So far I simply display the DataTable to a GridView.
I can create custom columns that do simple functions, for example:
ReturnVal = UnitPrice - Discount
What I would like to do is have a little more flaxability without
creating stored procedures, such as:
if Customer.Sales > 100 then
ReturnVal = UnitPrice - Discount
else
ReturnVal = UnitPrice
I have tried, and failed, to base the GridView on the BLL rather than
the DataTable in the DAL. I don't quite think I've got on top of
Partial classes yet, when I try to add the new function I can't get it
displayed in the GridView.
RE: Custom Columns in GridView
am 24.01.2008 12:36:01 von rodoopus
Two things you need to realize about the GridView Control. First it was
designed to be used in a declarative environment which the old DataGrid did
not support. âThank you God!â And because of itâs declarative nature it was
also meant to be used with the DataSource controls. What I hate about the
model is that it is too restrictive. I see tons of questions of people have
one issue or another with these controls that were suppose to be so easy to
use.
There is another property called DataSource that can be a life saver but I
will require you to write code. Remember normally you use DataSourceID to
which you wire a DataSource control. But DataSource will accept a dataset or
datatable which then makes things a little easier if you are building your
own middle tier. Write you methods so that they return a dataset or
datatable and hook it to the Gridview control with code
Dim b as new myBusiness.MyBll
GridView1.Datasource = b.GetData()
GridView1.DataBind()
Thatâs it! Of course almost immediately, you will realize that you need
more control over columns so it is possible to programmatically perform
column definitions that will allow you to customize validation, formatting
and event templates field all done programmatically.
The moral of the story is that if you want quick and dirty use the
declarative model but if you need control go to the old stand-by write code.
Use the empirical model.
Warning
With new power comes responsibility. The Declarative model freed you from
certain burdens associated with the Page Life Cycle. When you start coding
this is not the case now you have the responsibility of managing postbacks,
viewstate and other Data Binding issues. I guess the old say still applies
âYous pays me now or Yous pays me laterâ :-)
--
aaa
"andytidy@gmail.com" wrote:
> After going through some newbie examples I've created a DAL and BLL
> for my project. So far I simply display the DataTable to a GridView.
> I can create custom columns that do simple functions, for example:
>
> ReturnVal = UnitPrice - Discount
>
> What I would like to do is have a little more flaxability without
> creating stored procedures, such as:
>
> if Customer.Sales > 100 then
> ReturnVal = UnitPrice - Discount
> else
> ReturnVal = UnitPrice
>
> I have tried, and failed, to base the GridView on the BLL rather than
> the DataTable in the DAL. I don't quite think I've got on top of
> Partial classes yet, when I try to add the new function I can't get it
> displayed in the GridView.
>
RE: Custom Columns in GridView
am 24.01.2008 15:00:02 von rodoopus
I have a piece of demo code that might give some ideas give me an email
address and I will be glad to send it to you
--
aaa
"andytidy@gmail.com" wrote:
> After going through some newbie examples I've created a DAL and BLL
> for my project. So far I simply display the DataTable to a GridView.
> I can create custom columns that do simple functions, for example:
>
> ReturnVal = UnitPrice - Discount
>
> What I would like to do is have a little more flaxability without
> creating stored procedures, such as:
>
> if Customer.Sales > 100 then
> ReturnVal = UnitPrice - Discount
> else
> ReturnVal = UnitPrice
>
> I have tried, and failed, to base the GridView on the BLL rather than
> the DataTable in the DAL. I don't quite think I've got on top of
> Partial classes yet, when I try to add the new function I can't get it
> displayed in the GridView.
>
Re: Custom Columns in GridView
am 31.01.2008 00:36:29 von andytidy
On Jan 25, 1:00=A0am, Angel wrote:
> I have a piece of demo code that might give some ideas give me an email
> address and I will be glad to send it to =A0you
> --
> aaa
>
>
>
> "andyt...@gmail.com" wrote:
> > After going through some newbie examples I've created a DAL and BLL
> > for my project. So far I simply display the DataTable to a GridView.
> > I can create custom columns that do simple functions, for example:
>
> > ReturnVal =3D UnitPrice - Discount
>
> > What I would like to do is have a little more flaxability without
> > creating stored procedures, such as:
>
> > if Customer.Sales > 100 then
> > =A0 =A0 ReturnVal =3D UnitPrice - Discount
> > else
> > =A0 =A0 ReturnVal =3D UnitPrice
>
> > I have tried, and failed, to base the GridView on the BLL rather than
> > the DataTable in the DAL. I don't quite think I've got on top of
> > Partial classes yet, when I try to add the new function I can't get it
> > displayed in the GridView.- Hide quoted text -
>
> - Show quoted text -
I guess what I'm looking for is a nice robust BLL. The MS examples go
a long way but I need to see what happens when I customize or extend
the DAL tables. It would seem that if I do extend the DAL tables in my
BLL I can't use the groovy wizards and tools for quick building of
controls.
The 3-tier method is better in this version, I just can't use all the
features of the new whiz bang controls.
So I will go the long way round and populate the lists, do the paging
and the details pages myself, the good ol' write code method.
Thanks for your help.