由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - datagrid help
相关主题
How to Call Stored Procedure in C# .Net?static or else?
how to generate table in visual C#Drawbacks of using static
asp.net随机排列,怎么分页Button's refresh problem
一道mcad考试题求解(有关DataAdapter)Free Video Training: ASP.NET MVC 3 Features
hintresting datagrid
Bulk merge?ASP.NET IIS6 Hanging problem
control array in .netVisual Studio.net is buggy.
请问可能对C# dataSet作query吗?[转载] C#.NET DATAGRID 问题请教
相关话题的讨论汇总
话题: datagrid话题: data话题: page话题: control话题: rows
进入DotNet版参与讨论
1 (共1页)
s***d
发帖数: 14
1
Sorry, can't type Chinese here. I am kind of new to ASP.NET, and now I face a
question about DataGrid. On a web page which is basically a data entry page, I
want the user to be able to add new data rows (three Textboxese per row) and
once the user click on a button the whole table will be saved to database.
Since all rows have the same structure, my natural structure was to use
DataSet and DataGrid:
1. Upon adding new rows; just add rows to the backend DataTable and re-bind to
the DataGrid;
2. O
w**w
发帖数: 5391
2
this one is a little complicated, you have to generate html code from it.
we did similiar thing recently, but with buying a 3rd party control.

【在 s***d 的大作中提到】
: Sorry, can't type Chinese here. I am kind of new to ASP.NET, and now I face a
: question about DataGrid. On a web page which is basically a data entry page, I
: want the user to be able to add new data rows (three Textboxese per row) and
: once the user click on a button the whole table will be saved to database.
: Since all rows have the same structure, my natural structure was to use
: DataSet and DataGrid:
: 1. Upon adding new rows; just add rows to the backend DataTable and re-bind to
: the DataGrid;
: 2. O

p*p
发帖数: 75
3
"on PostBack, the DataGrid1.DataSource is null"
Yes, it's right. This is the basic concept must bear in mind. in ASP.NET, the
Control does not hold the Data. Although DataGrid, Repeater are called
Data-Bound controls, the Control can access to the data only when the
DataBind() is called:
if (!IsPostBack)
{
datagrid.DataSource = data;
datagrid.DataBind(); // datagrid use DataSource
to populate the controls
}
when posted back, the datagrid has no i

【在 s***d 的大作中提到】
: Sorry, can't type Chinese here. I am kind of new to ASP.NET, and now I face a
: question about DataGrid. On a web page which is basically a data entry page, I
: want the user to be able to add new data rows (three Textboxese per row) and
: once the user click on a button the whole table will be saved to database.
: Since all rows have the same structure, my natural structure was to use
: DataSet and DataGrid:
: 1. Upon adding new rows; just add rows to the backend DataTable and re-bind to
: the DataGrid;
: 2. O

s***d
发帖数: 14
4
Thanks.
But, I want to use the DataGrid as a container of TextBox(es), i.e. originally
the datasource is merely a bunch of empty strings or nulls. It will only make
sense when the page is sent back to the user and the user enters data to the
textboxes in the datagrid, and then I get data from the datagrid and save them
to a session.
Probably DataGrid is mainly to show already-available data and be able to
ocassionaly modify some of them. DataGrid may not be good for 100% data entry
form.
Thanks

【在 p*p 的大作中提到】
: "on PostBack, the DataGrid1.DataSource is null"
: Yes, it's right. This is the basic concept must bear in mind. in ASP.NET, the
: Control does not hold the Data. Although DataGrid, Repeater are called
: Data-Bound controls, the Control can access to the data only when the
: DataBind() is called:
: if (!IsPostBack)
: {
: datagrid.DataSource = data;
: datagrid.DataBind(); // datagrid use DataSource
: to populate the controls

r****y
发帖数: 26819
5
and EnableViewState default is to be true. Manually set it to true is not
necessary. Only manually set to false.

【在 s***d 的大作中提到】
: Thanks.
: But, I want to use the DataGrid as a container of TextBox(es), i.e. originally
: the datasource is merely a bunch of empty strings or nulls. It will only make
: sense when the page is sent back to the user and the user enters data to the
: textboxes in the datagrid, and then I get data from the datagrid and save them
: to a session.
: Probably DataGrid is mainly to show already-available data and be able to
: ocassionaly modify some of them. DataGrid may not be good for 100% data entry
: form.
: Thanks

p*p
发帖数: 75
6
it makes no difference to me for the two modes:
1. create a new object in memory
2. display the object with a data-bound control, such as DataGrid
3. let user enter data into the control, and post back
4. extract data from the control and save in the object in memory
5. save the new object into the database
or
1. display a page with empty controls
2. let user enter data into the control, and post back
3. create a new object in memory
3. extract data from the data and save in the object in memory

【在 s***d 的大作中提到】
: Thanks.
: But, I want to use the DataGrid as a container of TextBox(es), i.e. originally
: the datasource is merely a bunch of empty strings or nulls. It will only make
: sense when the page is sent back to the user and the user enters data to the
: textboxes in the datagrid, and then I get data from the datagrid and save them
: to a session.
: Probably DataGrid is mainly to show already-available data and be able to
: ocassionaly modify some of them. DataGrid may not be good for 100% data entry
: form.
: Thanks

s***d
发帖数: 14
7
Thanks again.
My problem is I don't know how to 'extract data from the control and save in
the object in memory' (step 4).
From what I've learned, in Page_Load (postback), I need re-create the DataGrid
first, and before any event handler is called, ASP.NET page handler tries to
match it with ViewState and also update with data just updated by the user, if
there's any.
There are a couples of problems:
1. Unlike other basic controls, DataGrid, however, doesn't have properties
like 'Text' or Select

【在 p*p 的大作中提到】
: it makes no difference to me for the two modes:
: 1. create a new object in memory
: 2. display the object with a data-bound control, such as DataGrid
: 3. let user enter data into the control, and post back
: 4. extract data from the control and save in the object in memory
: 5. save the new object into the database
: or
: 1. display a page with empty controls
: 2. let user enter data into the control, and post back
: 3. create a new object in memory

s***d
发帖数: 14
8
I think I got it.
I need recover/update the data inside the datagrid in Page_Load upon postback,
and then do the datagrid1.datasource = mysource, and then do the
datagrid1.DataBind().
To retrieve data inside the datagrid, just loop thru each item and use
'FindControl' function.
My mistake was that I updated the mysource in the event handler (but_click)
instead of Page_Load, but I had to in Page_Load give the datagrid a datasource
so I gave it the original, pre-updated one, thus all changes were

【在 p*p 的大作中提到】
: it makes no difference to me for the two modes:
: 1. create a new object in memory
: 2. display the object with a data-bound control, such as DataGrid
: 3. let user enter data into the control, and post back
: 4. extract data from the control and save in the object in memory
: 5. save the new object into the database
: or
: 1. display a page with empty controls
: 2. let user enter data into the control, and post back
: 3. create a new object in memory

p*p
发帖数: 75
9

Look at DataGridItem class. In DataGrid, a property called Items which is a
collection of DataGridItem objects. Each of them represents a row. It can be
considered as a container of the controls for a row. If you look at its
definition, in fact, it inherits from TableRow.
DataGrid
if
You are right. In fact, no matter initial request or postback, all the
controls in the control hierarchy need to be created in the first place. If
you create it by "new Datagrid" like, you need to create it and ins

【在 s***d 的大作中提到】
: Thanks again.
: My problem is I don't know how to 'extract data from the control and save in
: the object in memory' (step 4).
: From what I've learned, in Page_Load (postback), I need re-create the DataGrid
: first, and before any event handler is called, ASP.NET page handler tries to
: match it with ViewState and also update with data just updated by the user, if
: there's any.
: There are a couples of problems:
: 1. Unlike other basic controls, DataGrid, however, doesn't have properties
: like 'Text' or Select

p*p
发帖数: 75
10

postback,
to retrieve the value, may use e.Item.Cells[2].Text, e is
DataGridItemEventArgs.
datasource
(so
values.
3.
is
example,
some
the

【在 s***d 的大作中提到】
: I think I got it.
: I need recover/update the data inside the datagrid in Page_Load upon postback,
: and then do the datagrid1.datasource = mysource, and then do the
: datagrid1.DataBind().
: To retrieve data inside the datagrid, just loop thru each item and use
: 'FindControl' function.
: My mistake was that I updated the mysource in the event handler (but_click)
: instead of Page_Load, but I had to in Page_Load give the datagrid a datasource
: so I gave it the original, pre-updated one, thus all changes were

w******d
发帖数: 675
11
用asp的时候做过类似的东东,那时候没有datagrid.
用datagrid感觉不太顺手,反而更复杂。
几个礼拜前用datagrid,等做的差不多了发现没有用asp节省时间(可能俺很菜),所以
又抛开vs,用写asp的方式写了个aspx.

a
I
to
DataGrid
set
case.
in

【在 s***d 的大作中提到】
: Sorry, can't type Chinese here. I am kind of new to ASP.NET, and now I face a
: question about DataGrid. On a web page which is basically a data entry page, I
: want the user to be able to add new data rows (three Textboxese per row) and
: once the user click on a button the whole table will be saved to database.
: Since all rows have the same structure, my natural structure was to use
: DataSet and DataGrid:
: 1. Upon adding new rows; just add rows to the backend DataTable and re-bind to
: the DataGrid;
: 2. O

m**********e
发帖数: 19
12
hmm. Don't agree. hehe
I think datagrid is actually pretty powerful.


face
page,
and
re-bind
will

【在 w******d 的大作中提到】
: 用asp的时候做过类似的东东,那时候没有datagrid.
: 用datagrid感觉不太顺手,反而更复杂。
: 几个礼拜前用datagrid,等做的差不多了发现没有用asp节省时间(可能俺很菜),所以
: 又抛开vs,用写asp的方式写了个aspx.
:
: a
: I
: to
: DataGrid
: set

p*p
发帖数: 75
13
disagree. :)
Datagrid is flexible, but not powerful.
it's flexible, because it does nothing actually. :)


database.
manually
fields
I

【在 m**********e 的大作中提到】
: hmm. Don't agree. hehe
: I think datagrid is actually pretty powerful.
:
: 以
: face
: page,
: and
: re-bind
: will

1 (共1页)
进入DotNet版参与讨论
相关主题
[转载] C#.NET DATAGRID 问题请教h
问一个ASP.NET界面的问题,诚恳一问,谢谢!Bulk merge?
asp.netcontrol array in .net
Add controls into web form dynamically?请问可能对C# dataSet作query吗?
How to Call Stored Procedure in C# .Net?static or else?
how to generate table in visual C#Drawbacks of using static
asp.net随机排列,怎么分页Button's refresh problem
一道mcad考试题求解(有关DataAdapter)Free Video Training: ASP.NET MVC 3 Features
相关话题的讨论汇总
话题: datagrid话题: data话题: page话题: control话题: rows