Please Help!!! I've been suffering with these

H

Hai Nguyen

I fill all those datagrids into a place holder.

I'm really frustrated now. I just created another version which does not use
datagrid. I use Table of Web Control, everything seemed work fine until I
started collecting data. Fromdate, todate have textboxes for user to enter
values. I have a submit button, I don't know why everytime I hit button, all
the values are gone. My best guess is whenever i hit the button the
application has to postback, therefore my array of datagrids(or web tables)
are NULL.

Is there a way that I can collect data from these tables (remember these
tables are also dynamically change; hence I need help so much, I never built
any programatic talbes like these before)


Month fromdate todate Values
Month1
Month2
Month3
Month4
Month5
Month6
Month7
Month8
Month9
Month10
Month11
Month12
 
A

Alvin Bruney

Hai,
one of the reasons you are having so much problems is that you keep
constantly changing your design when you bump into a problem. You should try
your best to resolve the problem if you think you have a good design and go
on from there. I've been following your posts over usenet and that is what
has caught my eye.

Lets forget about how you want to present the data for a while and
concentrate on your data structures and business logic. One option is to
build out a dataset. Each row in the dataset will consist of a month row.
You should have 12 rows. Your dataset would then need 4 columns (according
to your specs): one for month, fromdate, todate and values. The good thing
about the dataset is that it is extensible so that if you wanted to add
another column such as values2 you wouldn't have to go rebuild the world to
do it. Manipulating this in-memory grid to find data would be trivial as
well. Here is some code to accomplish this.

DataSet dsTemp = new DataSet();
DataTable Tables = new DataTable();
dsTemp.Tables.Add(Tables);

dsTemp.Tables[0].Columns.Add( "Month", System.Type.GetType(
"System.String" ) );
dsTemp.Tables[0].Columns.Add( "FromDate", System.Type.GetType(
"System.String" ) );
dsTemp.Tables[0].Columns.Add( "Todate", System.Type.GetType(
"System.String" ) );
dsTemp.Tables[0].Columns.Add( "values", System.Type.GetType(
"System.String" ) );

The result of this code builds this:
Month fromdate todate Values

You now add months 1 thru 12 like so

for(int col = 0; col < 12; col++)
{
DataRow myRow = dsTemp.Tables[0].NewRow();
myRow[0]= monthvalue;
myRow[1]= fromdate;
myRow[2]= todatemonthvalue;
myRow[3]= value;
dsTemp.Tables[0].Rows.Add(myRow);

}

The result of this code builds your table exacly how you specified it in
your Original Post. Now you can worry about presenting this data. It's
easier to use a datagrid because the datagrid has internal support for
editing data. You can also bind this data to a repeater, or datalist. If you
use a datagrid, add an edit column to your datagrid in the designer. This
creates an extra column with an edit button. Bind your code to the new
dataset.

Once you have gotten this far, you need to know how to put the datagrid in
edit mode. For that, check this website http://www.datagridgirl.com/ Once
you have the data from the grid back in the dataset, write a routine to push
the data from the datagrid into your datastore.
 
H

Hai Nguyen

Thank you for being patient with me Alvin. Your long post has widen my
understandings of datagrid.

Again, with deep regards.
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top