473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Confusing design considerations

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.
Nov 18 '05 #1
4 1107
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" <gr****@willwyatt.com> wrote in message
news:28**************************@posting.google.c 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.

Nov 18 '05 #2
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" <fr**@here.there> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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" <gr****@willwyatt.com> wrote in message
news:28**************************@posting.google.c 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.


Nov 18 '05 #3
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" <fr**@here.there> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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" <gr****@willwyatt.com> wrote in message
news:28**************************@posting.google .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.



Nov 18 '05 #4
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.

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jose Perez | last post by:
Hello all, I am trying to correctly model the relationship between products and versions within my db. The problem I have is how to store the version data. I need to collect the following...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
21
by: Litron | last post by:
Appologies, this isn't really a javascript specific question.... Just wondering what the current size standard is for web-page design... it used to be 800 x 600 pxls (which seems quite small...
25
by: John Morgan | last post by:
Though I have designed and implemented a number of large reasonably well received web sites I do not consider myself a graphics designer I am now for the first time going to work with a ...
3
by: Will Honea | last post by:
I just got stuck with cleaning up a mess of records for a group I belong to - circa 80k memebers - that are being kept on a variety of spreadsheets and Access databases by a bunch of different...
4
by: Will | last post by:
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...
48
by: Tony | last post by:
How much bloat does the STL produce? Is it a good design wrt code bloat? Do implementations vary much? Tony
28
by: Alan Isaac | last post by:
I have a class whose instances should only receive attribute assignments for attributes that were created at inititialization. If slots are not appropriate, what is the Pythonic design for this? ...
19
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
1
by: Olaf | last post by:
Hi, I try to design a program which has to run on console. There is only one exe/binary and depend on the calling name argv the different tasks/commands should be performed as aliases. It's the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.