avatar
s*d
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
avatar
w*w
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

avatar
p*p
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

avatar
s*d
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

avatar
r*y
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

avatar
p*p
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

avatar
s*d
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

avatar
s*d
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

avatar
p*p
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

avatar
p*p
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

avatar
w*d
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

avatar
m*e
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

avatar
p*p
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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。