Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Confusing design considerations

Reply
Thread Tools

Confusing design considerations

 
 
Will
Guest
Posts: n/a
 
      01-22-2004
Hi all.
I'm trying to figure out how to design a WebForm app that may have
more than one bound DataGrid. What I want to accomplish is to create a
"helper" class that I can reuse for each of the DataGrids, as well as
in different projects.
So here is what I have come up with so far.

The first part of bound DataGrids I wanted to "consolidate" were some
of the events. For instance, lets say I have two grids dgDogs and
dgCats.
Each of the grids are editable. I want to find a way to reuse the
DataGrid events, so I created a helper class called
DataGridEventHelper. This class should hold at least the event classes
I want to reuse.

What I can't figure out how to do is DataBind() the datagrid from the
HelperClass. Once I figure out how to do this, then I think I can
extend the DataGridEventHelper class to do Lots Of Good Things. But
for now, it is just giving me a headache.

So, here is some of my code-behind for the aspx page and the code for
the helper class.

//----Code-behind code starts here
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
dgDogLoad();
}
}

public void dgDogLoad()
{
DataSet ds = new DataSet();
AnimalServices AS = new AnimalServices();
ds = AS.DogLookup(servername, database, "German Shepherd");
dgDog.DataSource = ds.Tables[0];
dgDog.DataBind();
}

public void dgCatLoad()
{
DataSet ds = new DataSet();
AnimalServices AS = new AnimalServices();
ds = AS.CatLookup(servername, database, "Russian Blue");
dgCat.DataSource = ds.Tables[0];
dgCat.DataBind();
}

private void InitializeComponent()
{
DataGridEventHelper dgeh = new DataGridEventHelper();
dgDog.EditCommand += new
DataGridCommandEventHandler(dgeh.DataGridEditComma nd);
dgCat.EditCommand += new
DataGridCommandEventHandler(dgeh.DataGridEditComma nd);
}

//----END OF Code-behind code



//----DataGridEventHelper code

public void DataGridEditCommand(object source,
DataGridCommandEventArgs e)
{
DataGrid dg = (DataGrid)source;
dg.EditItemIndex = e.Item.ItemIndex;

// This is what I can't figure out how to do.
// I need to DataBind() the datagrid I just came from.
// But, if I'm editing the dgDog grid, how do I call dgDog from this
code.

}
//----END OF DataGridEventHelper code

I though trying to "consolidate" the dgDogLoad and dgCatLoad code into
something like dgAnimalLoad that would be in the DataGridEventHelper
class and passing in some parameters like the AnimalServices.DogLoad
or AnimalServices.CatLoad, but I can't figure out how to do that
either.
If anyone has any advice, I'd appreciate it. Thanks.
 
Reply With Quote
 
 
 
 
Nick
Guest
Posts: n/a
 
      01-22-2004
Will,

Are you saying you want to consume the events of a DataGrid, but you have
duplication in so much as you do the same things with the events that come
back, but on different grids? You can share the events if this is the case,
or create a descendant grid control for reuse. From what you mention below,
I couldnt fully understand what you was trying to achieve. My main concern
would be duplication, and my last concern would be resuse.

HTH

N.

"Will" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi all.
> I'm trying to figure out how to design a WebForm app that may have
> more than one bound DataGrid. What I want to accomplish is to create a
> "helper" class that I can reuse for each of the DataGrids, as well as
> in different projects.
> So here is what I have come up with so far.
>
> The first part of bound DataGrids I wanted to "consolidate" were some
> of the events. For instance, lets say I have two grids dgDogs and
> dgCats.
> Each of the grids are editable. I want to find a way to reuse the
> DataGrid events, so I created a helper class called
> DataGridEventHelper. This class should hold at least the event classes
> I want to reuse.
>
> What I can't figure out how to do is DataBind() the datagrid from the
> HelperClass. Once I figure out how to do this, then I think I can
> extend the DataGridEventHelper class to do Lots Of Good Things. But
> for now, it is just giving me a headache.
>
> So, here is some of my code-behind for the aspx page and the code for
> the helper class.
>
> //----Code-behind code starts here
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (!IsPostBack)
> {
> dgDogLoad();
> }
> }
>
> public void dgDogLoad()
> {
> DataSet ds = new DataSet();
> AnimalServices AS = new AnimalServices();
> ds = AS.DogLookup(servername, database, "German Shepherd");
> dgDog.DataSource = ds.Tables[0];
> dgDog.DataBind();
> }
>
> public void dgCatLoad()
> {
> DataSet ds = new DataSet();
> AnimalServices AS = new AnimalServices();
> ds = AS.CatLookup(servername, database, "Russian Blue");
> dgCat.DataSource = ds.Tables[0];
> dgCat.DataBind();
> }
>
> private void InitializeComponent()
> {
> DataGridEventHelper dgeh = new DataGridEventHelper();
> dgDog.EditCommand += new
> DataGridCommandEventHandler(dgeh.DataGridEditComma nd);
> dgCat.EditCommand += new
> DataGridCommandEventHandler(dgeh.DataGridEditComma nd);
> }
>
> //----END OF Code-behind code
>
>
>
> //----DataGridEventHelper code
>
> public void DataGridEditCommand(object source,
> DataGridCommandEventArgs e)
> {
> DataGrid dg = (DataGrid)source;
> dg.EditItemIndex = e.Item.ItemIndex;
>
> // This is what I can't figure out how to do.
> // I need to DataBind() the datagrid I just came from.
> // But, if I'm editing the dgDog grid, how do I call dgDog from this
> code.
>
> }
> //----END OF DataGridEventHelper code
>
> I though trying to "consolidate" the dgDogLoad and dgCatLoad code into
> something like dgAnimalLoad that would be in the DataGridEventHelper
> class and passing in some parameters like the AnimalServices.DogLoad
> or AnimalServices.CatLoad, but I can't figure out how to do that
> either.
> If anyone has any advice, I'd appreciate it. Thanks.



 
Reply With Quote
 
 
 
 
news.central.cox.net
Guest
Posts: n/a
 
      01-23-2004
I have an app where the user may user 1 to 6 grids. Some of the event, like
EditCommand or CancelCommand, are the same for every grid. I'd like to be
able to reuse the same event for each of the grids, and reuse the whole grid
helpers in another project which is why I thought I'd make it a class.

Also, my data access scenarios are similar enough for all the grids that I
think I could reuse the data access methods as well. I guess I'm not
familiar enough with OOP to really understand if I'm wanting to create some
kind of base class that I would use that would have things like event and
data access methods already defined. Then I could extend the base class to
the specific situation without having to go through the entire data access /
event creation / event wiring procedure I go through now every time I create
a grid.

Thanks for helping. Hope I'm being clearer.

"Nick" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Will,
>
> Are you saying you want to consume the events of a DataGrid, but you have
> duplication in so much as you do the same things with the events that come
> back, but on different grids? You can share the events if this is the

case,
> or create a descendant grid control for reuse. From what you mention

below,
> I couldnt fully understand what you was trying to achieve. My main

concern
> would be duplication, and my last concern would be resuse.
>
> HTH
>
> N.
>
> "Will" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > Hi all.
> > I'm trying to figure out how to design a WebForm app that may have
> > more than one bound DataGrid. What I want to accomplish is to create a
> > "helper" class that I can reuse for each of the DataGrids, as well as
> > in different projects.
> > So here is what I have come up with so far.
> >
> > The first part of bound DataGrids I wanted to "consolidate" were some
> > of the events. For instance, lets say I have two grids dgDogs and
> > dgCats.
> > Each of the grids are editable. I want to find a way to reuse the
> > DataGrid events, so I created a helper class called
> > DataGridEventHelper. This class should hold at least the event classes
> > I want to reuse.
> >
> > What I can't figure out how to do is DataBind() the datagrid from the
> > HelperClass. Once I figure out how to do this, then I think I can
> > extend the DataGridEventHelper class to do Lots Of Good Things. But
> > for now, it is just giving me a headache.
> >
> > So, here is some of my code-behind for the aspx page and the code for
> > the helper class.
> >
> > //----Code-behind code starts here
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > if (!IsPostBack)
> > {
> > dgDogLoad();
> > }
> > }
> >
> > public void dgDogLoad()
> > {
> > DataSet ds = new DataSet();
> > AnimalServices AS = new AnimalServices();
> > ds = AS.DogLookup(servername, database, "German Shepherd");
> > dgDog.DataSource = ds.Tables[0];
> > dgDog.DataBind();
> > }
> >
> > public void dgCatLoad()
> > {
> > DataSet ds = new DataSet();
> > AnimalServices AS = new AnimalServices();
> > ds = AS.CatLookup(servername, database, "Russian Blue");
> > dgCat.DataSource = ds.Tables[0];
> > dgCat.DataBind();
> > }
> >
> > private void InitializeComponent()
> > {
> > DataGridEventHelper dgeh = new DataGridEventHelper();
> > dgDog.EditCommand += new
> > DataGridCommandEventHandler(dgeh.DataGridEditComma nd);
> > dgCat.EditCommand += new
> > DataGridCommandEventHandler(dgeh.DataGridEditComma nd);
> > }
> >
> > //----END OF Code-behind code
> >
> >
> >
> > //----DataGridEventHelper code
> >
> > public void DataGridEditCommand(object source,
> > DataGridCommandEventArgs e)
> > {
> > DataGrid dg = (DataGrid)source;
> > dg.EditItemIndex = e.Item.ItemIndex;
> >
> > // This is what I can't figure out how to do.
> > // I need to DataBind() the datagrid I just came from.
> > // But, if I'm editing the dgDog grid, how do I call dgDog from this
> > code.
> >
> > }
> > //----END OF DataGridEventHelper code
> >
> > I though trying to "consolidate" the dgDogLoad and dgCatLoad code into
> > something like dgAnimalLoad that would be in the DataGridEventHelper
> > class and passing in some parameters like the AnimalServices.DogLoad
> > or AnimalServices.CatLoad, but I can't figure out how to do that
> > either.
> > If anyone has any advice, I'd appreciate it. Thanks.

>
>



 
Reply With Quote
 
will
Guest
Posts: n/a
 
      01-23-2004
Sorry, switched readers.

news.central.cox.net wrote:
> I have an app where the user may user 1 to 6 grids. Some of the event, like
> EditCommand or CancelCommand, are the same for every grid. I'd like to be
> able to reuse the same event for each of the grids, and reuse the whole grid
> helpers in another project which is why I thought I'd make it a class.
>
> Also, my data access scenarios are similar enough for all the grids that I
> think I could reuse the data access methods as well. I guess I'm not
> familiar enough with OOP to really understand if I'm wanting to create some
> kind of base class that I would use that would have things like event and
> data access methods already defined. Then I could extend the base class to
> the specific situation without having to go through the entire data access /
> event creation / event wiring procedure I go through now every time I create
> a grid.
>
> Thanks for helping. Hope I'm being clearer.
>
> "Nick" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>
>>Will,
>>
>>Are you saying you want to consume the events of a DataGrid, but you have
>>duplication in so much as you do the same things with the events that come
>>back, but on different grids? You can share the events if this is the

>
> case,
>
>>or create a descendant grid control for reuse. From what you mention

>
> below,
>
>>I couldnt fully understand what you was trying to achieve. My main

>
> concern
>
>>would be duplication, and my last concern would be resuse.
>>
>>HTH
>>
>>N.
>>
>>"Will" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed) .com...
>>
>>>Hi all.
>>>I'm trying to figure out how to design a WebForm app that may have
>>>more than one bound DataGrid. What I want to accomplish is to create a
>>>"helper" class that I can reuse for each of the DataGrids, as well as
>>>in different projects.
>>>So here is what I have come up with so far.
>>>
>>>The first part of bound DataGrids I wanted to "consolidate" were some
>>>of the events. For instance, lets say I have two grids dgDogs and
>>>dgCats.
>>>Each of the grids are editable. I want to find a way to reuse the
>>>DataGrid events, so I created a helper class called
>>>DataGridEventHelper. This class should hold at least the event classes
>>>I want to reuse.
>>>
>>>What I can't figure out how to do is DataBind() the datagrid from the
>>>HelperClass. Once I figure out how to do this, then I think I can
>>>extend the DataGridEventHelper class to do Lots Of Good Things. But
>>>for now, it is just giving me a headache.
>>>
>>>So, here is some of my code-behind for the aspx page and the code for
>>>the helper class.
>>>
>>>//----Code-behind code starts here
>>>private void Page_Load(object sender, System.EventArgs e)
>>>{
>>>if (!IsPostBack)
>>>{
>>>dgDogLoad();
>>>}
>>>}
>>>
>>>public void dgDogLoad()
>>>{
>>>DataSet ds = new DataSet();
>>>AnimalServices AS = new AnimalServices();
>>>ds = AS.DogLookup(servername, database, "German Shepherd");
>>>dgDog.DataSource = ds.Tables[0];
>>>dgDog.DataBind();
>>>}
>>>
>>>public void dgCatLoad()
>>>{
>>>DataSet ds = new DataSet();
>>>AnimalServices AS = new AnimalServices();
>>>ds = AS.CatLookup(servername, database, "Russian Blue");
>>>dgCat.DataSource = ds.Tables[0];
>>>dgCat.DataBind();
>>>}
>>>
>>>private void InitializeComponent()
>>>{
>>>DataGridEventHelper dgeh = new DataGridEventHelper();
>>>dgDog.EditCommand += new
>>>DataGridCommandEventHandler(dgeh.DataGridEditCo mmand);
>>>dgCat.EditCommand += new
>>>DataGridCommandEventHandler(dgeh.DataGridEditCo mmand);
>>>}
>>>
>>>//----END OF Code-behind code
>>>
>>>
>>>
>>>//----DataGridEventHelper code
>>>
>>>public void DataGridEditCommand(object source,
>>>DataGridCommandEventArgs e)
>>>{
>>>DataGrid dg = (DataGrid)source;
>>>dg.EditItemIndex = e.Item.ItemIndex;
>>>
>>>// This is what I can't figure out how to do.
>>>// I need to DataBind() the datagrid I just came from.
>>>// But, if I'm editing the dgDog grid, how do I call dgDog from this
>>>code.
>>>
>>>}
>>>//----END OF DataGridEventHelper code
>>>
>>>I though trying to "consolidate" the dgDogLoad and dgCatLoad code into
>>>something like dgAnimalLoad that would be in the DataGridEventHelper
>>>class and passing in some parameters like the AnimalServices.DogLoad
>>>or AnimalServices.CatLoad, but I can't figure out how to do that
>>>either.
>>>If anyone has any advice, I'd appreciate it. Thanks.

>>
>>

>
>

 
Reply With Quote
 
will
Guest
Posts: n/a
 
      01-26-2004
So, I think I figured out a way to do this with deletegates.
Here is what I'm doing.

I created a new class called DeletegateTest:
//------- Class DelegateTest
public class DelegateTest
{
public DataGrid d = new DataGrid();

public delegate void TestClickHandler(object sender,
DataGridCommandEventArgs e);
public event TestClickHandler Click;

public void s_DataGridEditCommand(object source,
DataGridCommandEventArgs e, Template t)
{
if (Click != null)
{
DataGrid dg = (DataGrid)source;
dg.EditItemIndex = e.Item.ItemIndex;

t.GenericGridReloader(dg);

d = dg;
}
}
}
//------- End DelegateTest

And then in my form's InitializeComponent I have:
this.dgPhysicians.EditCommand += new
DataGridCommandEventHandler(EditCommandDelegate);

and a method:
public void EditCommandDelegate(object source, DataGridCommandEventArgs e)
{
DelegateTest dt = new DelegateTest();
dt.Click += new
HealthWeb.DelegateTest.TestClickHandler(EditComman dDelegate);
dt.s_DataGridEditCommand(source, e, this);
GenericGridReloader(dt.d);
}

GenericGridReloader is a method in the form's class that reloads the
datagrid.

Is the a "correct" way to do this? Or am I way off and only getting
lucky and my app will blow up some day? Thanks.



Will wrote:
> Hi all.
> I'm trying to figure out how to design a WebForm app that may have
> more than one bound DataGrid. What I want to accomplish is to create a
> "helper" class that I can reuse for each of the DataGrids, as well as
> in different projects.
> So here is what I have come up with so far.
>
> The first part of bound DataGrids I wanted to "consolidate" were some
> of the events. For instance, lets say I have two grids dgDogs and
> dgCats.
> Each of the grids are editable. I want to find a way to reuse the
> DataGrid events, so I created a helper class called
> DataGridEventHelper. This class should hold at least the event classes
> I want to reuse.
>
> What I can't figure out how to do is DataBind() the datagrid from the
> HelperClass. Once I figure out how to do this, then I think I can
> extend the DataGridEventHelper class to do Lots Of Good Things. But
> for now, it is just giving me a headache.
>
> So, here is some of my code-behind for the aspx page and the code for
> the helper class.
>
> //----Code-behind code starts here
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (!IsPostBack)
> {
> dgDogLoad();
> }
> }
>
> public void dgDogLoad()
> {
> DataSet ds = new DataSet();
> AnimalServices AS = new AnimalServices();
> ds = AS.DogLookup(servername, database, "German Shepherd");
> dgDog.DataSource = ds.Tables[0];
> dgDog.DataBind();
> }
>
> public void dgCatLoad()
> {
> DataSet ds = new DataSet();
> AnimalServices AS = new AnimalServices();
> ds = AS.CatLookup(servername, database, "Russian Blue");
> dgCat.DataSource = ds.Tables[0];
> dgCat.DataBind();
> }
>
> private void InitializeComponent()
> {
> DataGridEventHelper dgeh = new DataGridEventHelper();
> dgDog.EditCommand += new
> DataGridCommandEventHandler(dgeh.DataGridEditComma nd);
> dgCat.EditCommand += new
> DataGridCommandEventHandler(dgeh.DataGridEditComma nd);
> }
>
> //----END OF Code-behind code
>
>
>
> //----DataGridEventHelper code
>
> public void DataGridEditCommand(object source,
> DataGridCommandEventArgs e)
> {
> DataGrid dg = (DataGrid)source;
> dg.EditItemIndex = e.Item.ItemIndex;
>
> // This is what I can't figure out how to do.
> // I need to DataBind() the datagrid I just came from.
> // But, if I'm editing the dgDog grid, how do I call dgDog from this
> code.
>
> }
> //----END OF DataGridEventHelper code
>
> I though trying to "consolidate" the dgDogLoad and dgCatLoad code into
> something like dgAnimalLoad that would be in the DataGridEventHelper
> class and passing in some parameters like the AnimalServices.DogLoad
> or AnimalServices.CatLoad, but I can't figure out how to do that
> either.
> If anyone has any advice, I'd appreciate it. Thanks.

 
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
Interface design considerations sasuke Java 10 07-10-2009 08:24 PM
Design Considerations FancyDeadCat Cisco 0 09-17-2007 07:11 PM
asp.net web form layout design considerations help quintesv via DotNetMonster.com ASP .Net 1 09-27-2006 02:18 PM
Design Considerations Jonathan Wood ASP .Net 7 02-17-2006 03:49 AM
different design considerations for objects and tables eddiec C++ 2 07-20-2004 03:49 AM



Advertisments