Custom Columns in GridView

A

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

Angel

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†:)
 
A

Angel

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
 
A

andytidy

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









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

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

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top