By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Repeating section control in ASP.NET

P: n/a
When building a form using Infopath, you can define a repeating
section and stick form fields in that section. I'm curious if ASP.NET
has a similar control to make it easy to design something similar
using just ASP.NET (and not Infopath)? I'd hate to think that I'll
need to write all the javascript/dhtml to mimic that functionality and
I don't really feel the need to re-invent the wheel.
Has MS designed such a control? A 3rd party?

Thanks for your time and assistance!

Christoph
Nov 18 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
That's one of the best reasons for learning C# as the task of using
JavaScript becomes much less of a syntax and grammar burden.

So I may have to practice what I preach as I need a form with a textbox
control that gets filled out multiple times which seems to be the only
reasonable way to build nodes in an XML document using a client-side
application.

I don't like the idea of giving away this code. I wouldn't mind so much
but I have a competitor that wants everything I have the way it is so
I was thinking about building he XML document in the ViewState
where the code could run on the server while still allowing the operator
to review and revise before a final commit.

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/


"Christoph Boget" <jc*****@yahoo.com> wrote in message
news:uz**************@TK2MSFTNGP11.phx.gbl...
When building a form using Infopath, you can define a repeating
section and stick form fields in that section. I'm curious if ASP.NET
has a similar control to make it easy to design something similar
using just ASP.NET (and not Infopath)? I'd hate to think that I'll
need to write all the javascript/dhtml to mimic that functionality and
I don't really feel the need to re-invent the wheel.
Has MS designed such a control? A 3rd party?

Thanks for your time and assistance!

Christoph

Nov 18 '05 #2

P: n/a
"Christoph Boget" <jc*****@yahoo.com> wrote in message
news:uz****************@TK2MSFTNGP11.phx.gbl...
When building a form using Infopath, you can define a repeating
section and stick form fields in that section. I'm curious if ASP.NET
has a similar control to make it easy to design something similar
using just ASP.NET (and not Infopath)? I'd hate to think that I'll
need to write all the javascript/dhtml to mimic that functionality and
I don't really feel the need to re-invent the wheel.
Has MS designed such a control? A 3rd party?


Are you familiar with the Repeater and DataList controls? They can repeat
arbitrary sets of controls for you, one set per input data item.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #3

P: n/a
> > When building a form using Infopath, you can define a repeating
section and stick form fields in that section. I'm curious if ASP.NET
has a similar control to make it easy to design something similar
using just ASP.NET (and not Infopath)? I'd hate to think that I'll
need to write all the javascript/dhtml to mimic that functionality and
I don't really feel the need to re-invent the wheel.
Has MS designed such a control? A 3rd party?

Are you familiar with the Repeater and DataList controls? They can repeat
arbitrary sets of controls for you, one set per input data item.


I've looked at both of these and yes, they are really great for repeating
data coming from a datasource. However, what I need is something
that will repeat controls that will contain user input that will be posted
back to the server and ultimately inserted into a datastore. These are
the two things I can't figure out from reading (what little) documentation
on the repeating control:

* How to repeat a set of empty controls on the client side. For example,
let's say I have 3 input text boxes. Say, for 'First Name', 'Middle Name',
'Last Name'. And these text boxes appear on a form used to add people
to a table in the data store. I can display the first row of those blank
boxes
no problem. But I'm not show how I can make it so that the end user can
make it so that another, blank, row appears so they can add multiple people
in one shot.

* Related to the above, assuming it is possible, how would those new
controls be referenced in the code on the back end. It's easy enough to
reference the initial set of controls as I would just reference them by
name.
What would be the names of the new, dynamically generated controls (ie
the 3 input text boxes)?

The above is the context with which I was asking my original question.
I apologize for not being more clear.

Thank you for your time and assistance!

Christoph
Nov 18 '05 #4

P: n/a
"Christoph" <jc*****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
When building a form using Infopath, you can define a repeating
section and stick form fields in that section. I'm curious if ASP.NET
has a similar control to make it easy to design something similar
using just ASP.NET (and not Infopath)? I'd hate to think that I'll
need to write all the javascript/dhtml to mimic that functionality and
I don't really feel the need to re-invent the wheel.
Has MS designed such a control? A 3rd party? Are you familiar with the Repeater and DataList controls? They can repeat arbitrary sets of controls for you, one set per input data item.


I've looked at both of these and yes, they are really great for repeating
data coming from a datasource. However, what I need is something
that will repeat controls that will contain user input that will be posted
back to the server and ultimately inserted into a datastore. These are
the two things I can't figure out from reading (what little) documentation
on the repeating control:

* How to repeat a set of empty controls on the client side. For example,
let's say I have 3 input text boxes. Say, for 'First Name', 'Middle

Name', 'Last Name'. And these text boxes appear on a form used to add people
to a table in the data store. I can display the first row of those blank
boxes
no problem. But I'm not show how I can make it so that the end user can
make it so that another, blank, row appears so they can add multiple people in one shot.

* Related to the above, assuming it is possible, how would those new
controls be referenced in the code on the back end. It's easy enough to
reference the initial set of controls as I would just reference them by
name.
What would be the names of the new, dynamically generated controls (ie
the 3 input text boxes)?

The above is the context with which I was asking my original question.
I apologize for not being more clear.


Ok, no, ASP.NET doesn't do this. It's possible that you could do something
like this with ASP.NET 2.0, though I think you'd still wind up creating your
own control. See the most recent issue of MSDN Magazine for a discussion of
the new GridView control and how it works with the new DataSource controls.
It seems to me that one could have a DataSource control which would allow
you to add data client-side (perhaps as XML stored in a hidden field), but
which would then actually insert the changes into the database once the form
posted back.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #5

P: n/a
What you are trying to do is definitely possible in ASP.Net. It's not
exactly trivial but it also isn't terribly difficult once you get the hang
of the controls and classes involved. Undoubtedly, there are as many
possible ways to do it as there are readers of this board but if I were
doing what you're doing, I'd probably go like this:

You could create a DataSet and a Repeater. Assign a table in the DataSet as
the DataSource property of your Repeater using myRepeater.DataSource =
ds.Tables["myTable"];

Create a new row by using the NewRow method of the table and add it to the
table with ds.Tables["myTable"].Rows.Add(newRow);

Then use myRepeater.DataBind() to bind the table to your repeater. Now you
have a blank row and it will display the same template as your populated
rows but the values will be null. Make sure you test for IsDbNull and
handle that in your repeater templates.

In your ItemCommand handler of the repeater, you can save or cancel the new
row on postback and, if appropriate, create a new blank row for the next
cycle.

You could create your own repeater and inherit the
System.Web.UI.WebControls.Repeater and create your own template inheriting
the ITemplate interface.

You can find a simple example of creating your own repeater at
http://coltkwong.com/blogs/juliet/posts/467.aspx. The key thing on that
site is not her exact control but rather how simple it is to create a custom
repeater. There are probably hundreds of other custom repeater examples on
the net. I just know that I used her example as the starting point for
creating the repeater I am using in my current project at work and it has
made my life a lot easier.

Some keywords you may want to look up on google and MSDN are IsDbNull,
ITemplate, Templated Controls, DataBind, TemplateItem,
Repeater.OnDataBinding.

Hope that helps some,

Dale
"Christoph" <jc*****@yahoo.com> wrote in message
news:#N**************@TK2MSFTNGP10.phx.gbl...
When building a form using Infopath, you can define a repeating
section and stick form fields in that section. I'm curious if ASP.NET
has a similar control to make it easy to design something similar
using just ASP.NET (and not Infopath)? I'd hate to think that I'll
need to write all the javascript/dhtml to mimic that functionality and
I don't really feel the need to re-invent the wheel.
Has MS designed such a control? A 3rd party? Are you familiar with the Repeater and DataList controls? They can repeat arbitrary sets of controls for you, one set per input data item.


I've looked at both of these and yes, they are really great for repeating
data coming from a datasource. However, what I need is something
that will repeat controls that will contain user input that will be posted
back to the server and ultimately inserted into a datastore. These are
the two things I can't figure out from reading (what little) documentation
on the repeating control:

* How to repeat a set of empty controls on the client side. For example,
let's say I have 3 input text boxes. Say, for 'First Name', 'Middle

Name', 'Last Name'. And these text boxes appear on a form used to add people
to a table in the data store. I can display the first row of those blank
boxes
no problem. But I'm not show how I can make it so that the end user can
make it so that another, blank, row appears so they can add multiple people in one shot.

* Related to the above, assuming it is possible, how would those new
controls be referenced in the code on the back end. It's easy enough to
reference the initial set of controls as I would just reference them by
name.
What would be the names of the new, dynamically generated controls (ie
the 3 input text boxes)?

The above is the context with which I was asking my original question.
I apologize for not being more clear.

Thank you for your time and assistance!

Christoph

Nov 18 '05 #6

P: n/a
> Ok, no, ASP.NET doesn't do this. It's possible that you could do something
like this with ASP.NET 2.0, though I think you'd still wind up creating your own control. See the most recent issue of MSDN Magazine for a discussion of the new GridView control and how it works with the new DataSource controls. It seems to me that one could have a DataSource control which would allow
you to add data client-side (perhaps as XML stored in a hidden field), but
which would then actually insert the changes into the database once the form posted back.


Ok So I guess I'm just going to have to do this the old fashioned way with
DHTML, which is fine as I've done it often enough in the past. But if I do
it this way, I'm still left with my second issue/question -- how do I access
these new, dynamically created HTML form elements in the back end code?
In PHP, this was easy as I could just iterate through the $_POST (or the
$_REQUEST) arrays and just grab all the keys that matched the base name
of the control. It doesn't seem as if ASP.NET has anything close to that
for me to use. As such, I'm not sure how I'd be able to access the values
of those controls.
Just wanted to make a quick comment that I'd rather not post back to the
server to create the new row of form elements and instead create them
dynamically via the client. If I post back to create the form, accessing
the
new form elements/controls is a no brainer.

Thanks again for your time and assistance!

Christoph
Nov 18 '05 #7

P: n/a
"Christoph" <jc*****@yahoo.com> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
Ok, no, ASP.NET doesn't do this. It's possible that you could do something like this with ASP.NET 2.0, though I think you'd still wind up creating your
own control. See the most recent issue of MSDN Magazine for a discussion

of
the new GridView control and how it works with the new DataSource

controls.
It seems to me that one could have a DataSource control which would allow you to add data client-side (perhaps as XML stored in a hidden field), but which would then actually insert the changes into the database once the

form
posted back.


Ok So I guess I'm just going to have to do this the old fashioned way

with DHTML, which is fine as I've done it often enough in the past. But if I do it this way, I'm still left with my second issue/question -- how do I access these new, dynamically created HTML form elements in the back end code?
In PHP, this was easy as I could just iterate through the $_POST (or the
$_REQUEST) arrays and just grab all the keys that matched the base name
of the control. It doesn't seem as if ASP.NET has anything close to that
for me to use. As such, I'm not sure how I'd be able to access the values
of those controls.
Just wanted to make a quick comment that I'd rather not post back to the
server to create the new row of form elements and instead create them
dynamically via the client. If I post back to create the form, accessing
the
new form elements/controls is a no brainer.


ASP.NET has the Request.Form and Request.QueryString collections, which you
can use.

You know, if you get into writing ASP.NET custom controls, you could
probably create a control which would do exactly what you want. The user
would create as many repeats of the section(s) as he wants. Then, on the
eventual postback (once per Save, perhaps), when the control loads its
postback data, it would see the number of repeats, and would be able to
create that many copies of the repeating section. It could then load the
postback data into each repeat, producing on the server a copy of the data
which was gathered on the client.

In other words, good luck, and if you get it working, please post the source
code!
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #8

P: n/a
I agree.
I did this with a DataGrid control and a custom collection.
I have a button that says Add NewRecord.
When it is clicked I add a blank row to my collection and re-bind it to the
grid.
This works perfectly!

Joe Fallon

"Dale" <da************@msndotcomNot.Net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
What you are trying to do is definitely possible in ASP.Net. It's not
exactly trivial but it also isn't terribly difficult once you get the hang
of the controls and classes involved. Undoubtedly, there are as many
possible ways to do it as there are readers of this board but if I were
doing what you're doing, I'd probably go like this:

You could create a DataSet and a Repeater. Assign a table in the DataSet as the DataSource property of your Repeater using myRepeater.DataSource =
ds.Tables["myTable"];

Create a new row by using the NewRow method of the table and add it to the
table with ds.Tables["myTable"].Rows.Add(newRow);

Then use myRepeater.DataBind() to bind the table to your repeater. Now you have a blank row and it will display the same template as your populated
rows but the values will be null. Make sure you test for IsDbNull and
handle that in your repeater templates.

In your ItemCommand handler of the repeater, you can save or cancel the new row on postback and, if appropriate, create a new blank row for the next
cycle.

You could create your own repeater and inherit the
System.Web.UI.WebControls.Repeater and create your own template inheriting
the ITemplate interface.

You can find a simple example of creating your own repeater at
http://coltkwong.com/blogs/juliet/posts/467.aspx. The key thing on that
site is not her exact control but rather how simple it is to create a custom repeater. There are probably hundreds of other custom repeater examples on the net. I just know that I used her example as the starting point for
creating the repeater I am using in my current project at work and it has
made my life a lot easier.

Some keywords you may want to look up on google and MSDN are IsDbNull,
ITemplate, Templated Controls, DataBind, TemplateItem,
Repeater.OnDataBinding.

Hope that helps some,

Dale
"Christoph" <jc*****@yahoo.com> wrote in message
news:#N**************@TK2MSFTNGP10.phx.gbl...
> When building a form using Infopath, you can define a repeating
> section and stick form fields in that section. I'm curious if ASP.NET > has a similar control to make it easy to design something similar
> using just ASP.NET (and not Infopath)? I'd hate to think that I'll
> need to write all the javascript/dhtml to mimic that functionality and > I don't really feel the need to re-invent the wheel.
> Has MS designed such a control? A 3rd party?
Are you familiar with the Repeater and DataList controls? They can repeat arbitrary sets of controls for you, one set per input data item.


I've looked at both of these and yes, they are really great for repeating data coming from a datasource. However, what I need is something
that will repeat controls that will contain user input that will be posted back to the server and ultimately inserted into a datastore. These are
the two things I can't figure out from reading (what little) documentation on the repeating control:

* How to repeat a set of empty controls on the client side. For example, let's say I have 3 input text boxes. Say, for 'First Name', 'Middle

Name',
'Last Name'. And these text boxes appear on a form used to add people
to a table in the data store. I can display the first row of those blank boxes
no problem. But I'm not show how I can make it so that the end user can
make it so that another, blank, row appears so they can add multiple

people
in one shot.

* Related to the above, assuming it is possible, how would those new
controls be referenced in the code on the back end. It's easy enough to
reference the initial set of controls as I would just reference them by
name.
What would be the names of the new, dynamically generated controls (ie
the 3 input text boxes)?

The above is the context with which I was asking my original question.
I apologize for not being more clear.

Thank you for your time and assistance!

Christoph


Nov 18 '05 #9

P: n/a
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I agree.
I did this with a DataGrid control and a custom collection.
I have a button that says Add NewRecord.
When it is clicked I add a blank row to my collection and re-bind it to the grid.
This works perfectly!
Note that this isn't what the OP wanted. He wanted the added data to be
client-side until the user was done with the entire form. Also, he wasn't
talking about the typical datagrid. He was talking about a group of controls
which would repeat, once per input, but which could have new repeats added
to it on the client.
--
John Saunders
johnwsaundersiii at hotmail

"Dale" <da************@msndotcomNot.Net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
What you are trying to do is definitely possible in ASP.Net. It's not
exactly trivial but it also isn't terribly difficult once you get the hang
of the controls and classes involved. Undoubtedly, there are as many
possible ways to do it as there are readers of this board but if I were
doing what you're doing, I'd probably go like this:

You could create a DataSet and a Repeater. Assign a table in the DataSet
as
the DataSource property of your Repeater using myRepeater.DataSource =
ds.Tables["myTable"];

Create a new row by using the NewRow method of the table and add it to

the table with ds.Tables["myTable"].Rows.Add(newRow);

Then use myRepeater.DataBind() to bind the table to your repeater. Now

you
have a blank row and it will display the same template as your populated
rows but the values will be null. Make sure you test for IsDbNull and
handle that in your repeater templates.

In your ItemCommand handler of the repeater, you can save or cancel the

new
row on postback and, if appropriate, create a new blank row for the next
cycle.

You could create your own repeater and inherit the
System.Web.UI.WebControls.Repeater and create your own template inheriting the ITemplate interface.

You can find a simple example of creating your own repeater at
http://coltkwong.com/blogs/juliet/posts/467.aspx. The key thing on that
site is not her exact control but rather how simple it is to create a

custom
repeater. There are probably hundreds of other custom repeater examples

on
the net. I just know that I used her example as the starting point for
creating the repeater I am using in my current project at work and it has made my life a lot easier.

Some keywords you may want to look up on google and MSDN are IsDbNull,
ITemplate, Templated Controls, DataBind, TemplateItem,
Repeater.OnDataBinding.

Hope that helps some,

Dale
"Christoph" <jc*****@yahoo.com> wrote in message
news:#N**************@TK2MSFTNGP10.phx.gbl...
> > When building a form using Infopath, you can define a repeating
> > section and stick form fields in that section. I'm curious if

ASP.NET > > has a similar control to make it easy to design something similar
> > using just ASP.NET (and not Infopath)? I'd hate to think that I'll > > need to write all the javascript/dhtml to mimic that functionality and > > I don't really feel the need to re-invent the wheel.
> > Has MS designed such a control? A 3rd party?
> Are you familiar with the Repeater and DataList controls? They can

repeat
> arbitrary sets of controls for you, one set per input data item.

I've looked at both of these and yes, they are really great for repeating data coming from a datasource. However, what I need is something
that will repeat controls that will contain user input that will be posted back to the server and ultimately inserted into a datastore. These are the two things I can't figure out from reading (what little) documentation on the repeating control:

* How to repeat a set of empty controls on the client side. For example, let's say I have 3 input text boxes. Say, for 'First Name', 'Middle

Name',
'Last Name'. And these text boxes appear on a form used to add people
to a table in the data store. I can display the first row of those blank boxes
no problem. But I'm not show how I can make it so that the end user can make it so that another, blank, row appears so they can add multiple

people
in one shot.

* Related to the above, assuming it is possible, how would those new
controls be referenced in the code on the back end. It's easy enough to reference the initial set of controls as I would just reference them by name.
What would be the names of the new, dynamically generated controls (ie
the 3 input text boxes)?

The above is the context with which I was asking my original question.
I apologize for not being more clear.

Thank you for your time and assistance!

Christoph



Nov 18 '05 #10

P: n/a
> That's one of the best reasons for learning C# as the task of using
JavaScript becomes much less of a syntax and grammar burden.


Please elaborate on this? How does C# make using JS much less of
a burden?

thnx,
Christoph
Nov 18 '05 #11

P: n/a
For me, it was really easy to pick up on C# since I have years of experience
with js, and had been working with
VB.Net for about a year. Since the syntax for C# is a lot like js, and I was
familiar with the .net framework, picking
up C# was fairly easy to do.

Now, 2 years later, I find myself working on both C# and VB.Net projects
within the same week, or even the same
day, and have no real problems switching between the two.

I do, however, prefer to use C# over vb.Net. No real reason, it just seems
to flow better than vb.net for me.

Thx
Levi
"Christoph Boget" <jc*****@yahoo.com> wrote in message
news:e3*************@TK2MSFTNGP12.phx.gbl...
That's one of the best reasons for learning C# as the task of using
JavaScript becomes much less of a syntax and grammar burden.


Please elaborate on this? How does C# make using JS much less of
a burden?

thnx,
Christoph

Nov 18 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.