Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 6th, 2004, 04:20 PM
Authorized User
 
Join Date: Feb 2004
Location: Philadelphia, , USA.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Dynamic Forms with ASP.NET

Hello. This is a rather large question, so here goes... I am looking for a way to create an online form that displays information from a database in text boxes, which would allow the user to change the data and submit it to the database as an update. I have read over the examples in 'Beginning ASP.NET Databases Using VB.NET' and cannot find an example of what I need. Most of the examples involve displaying data from a DataSet in tables, not controls. That is, they display information in tabular form with the fields of the database occupying <td>s, not in text boxes or labels. More background on my project:

I have a SQL 2000 database that holds information on counties and agencies that handle their accounts. I want to build a form that displays those accounts and all their related fields. I have been successful in building a DataSet and populating the results of my SQL statement in a DataGrid, And I have been able to use the DataSet to loop through each row populating the form's fields into a table, like this:

Dim strCountyData As String
Dim r As DataRow
For each r in countyDataSet.Tables("dtCountyData").Rows
  strCountyData &= "<td>" & r("Collectable") & "</td>"
  ETC. ETC.
Next

This works when I want to write out the returned fields in HTML tables, but it really doesn't work well when I try putting those fields inside text boxes, or creating buttons to execute commands. Code such as this below does not work as the quotes interfere with the HTML produced (in this example, only the first word of the field is placed in the text box--the rest is cut off).

Dim strCountyData As String
Dim r As DataRow
For each r in countyDataSet.Tables("dtCountyData").Rows
   strCountyData &= "<b>" & r("Collectable") & " for: </b>"
   strCountyData &= "<input type=text value="
   strCountyData &= r("EntityName")
   strCountyData &= " />
   ETC. ETC.
Next

To get the data into controls, do I need to set up a template then bind the data somehow to the DataSet to be run through the template? I am reading 'Professional ASP.NET 1.0' where I have seen examples using data binding to populate controls, though I cannot figure out how to do so while looping through the rows of a DataSet.

Does anyone have any suggestions?

  #2 (permalink)  
Old February 7th, 2004, 01:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Check out this thread:

http://p2p.wrox.com/topic.asp?TOPIC_...rchTerms=table

Only instead of creating tables you would be creating textboxes like:

-------------------------------------------------
Dim txtnew As TextBox = New TextBox
-------------------------------------------------

Then set the text property of the newly created text box to your datasource:

-------------------------------------------------
txtnew.text = [data]
-------------------------------------------------

and add it to your form.

J
  #3 (permalink)  
Old February 9th, 2004, 12:09 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Datagrids allow you to create editable rows so you can change the data presented in them. If you need more specific control over the whole layout of the textbox set, you could use a datalist.

Dynamically creating controls can be problematic when you need to get at their values after a postback. If you know what types of controls you need to user (i.e. textboxes) then you can use the data listing controls (datagrid, datalist, etc) to create row templates and let the control handle the looping of the records and the maintenance of the control states and values.

The DataList control offers great flexibility of template layout while still providing the predefined event handlers you would want for data interaction (OnEditCommand, OnUpdateCommand, OnCancelCommand, etc). Take a look at the MSDN documentation for it: http://msdn.microsoft.com/library/de...webcontrol.asp

Peter
------------------------------------------------------
Work smarter, not harder.
  #4 (permalink)  
Old February 9th, 2004, 12:58 PM
Authorized User
 
Join Date: Feb 2004
Location: Philadelphia, , USA.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Over the weekend I did more searching online & found references to using a Repeater object with a DataSet as its source. I am trying that out right now & it seems to give me the flexibility I need in laying out the information for the user. Concerning postbacks & other event issues, I'll see what happens when I try updating, inserting & deleting records from the database.

Thanks.

  #5 (permalink)  
Old November 23rd, 2004, 06:38 AM
dsg dsg is offline
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there,
Really Hope you can point me in the right direction. It's similair to the problem you've had with displaying populated textboxs and dropdowns .

I have a datagrid and I post a selected row (ID) to another web page.
This other web page contains a form with quite a few dropdowns and textboxs (about 15) that get populated, so basically I need to drill down the information for a particular row selected.

I'll need to be able to edit and save information within this other form. I've tried using a datalist control but this means I can only edit one row at a time? I'd like to have just one submit button at the bottom and when this is clicked it saves the info for all the controls on thae page. Are there any other ways to accomplish this task. I'm using vis studio 2003 & Vb.net for my code behind pages

Many Thanks in advance for any advice.

Rgds
DSG

  #6 (permalink)  
Old November 23rd, 2004, 06:10 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There's no rule that says the ItemTemplate for a DataGrid/DataList/Repeater cannot contain editable controls. You can put editable controls in the item template so that you can have a single save/submit button. Then in the handler for that, you can iterate through all the items of the data listing control and grab the values from the editable controls in each item.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Dynamic ASP.NET Server Controls Using XML kwilliams XSLT 0 October 6th, 2006 01:42 PM
I need help with Frames and Forms in ASP.NET leex Classic ASP Basics 1 August 19th, 2004 11:44 PM
Creating an ASP.Net Application in VS.Net Maxood BOOK: Beginning ASP.NET 1.0 11 July 6th, 2004 03:09 PM
Creating ASP.NET Application in Visual Studio.NET Maxood ASP.NET 1.0 and 1.1 Basics 1 March 8th, 2004 01:56 PM



All times are GMT -4. The time now is 12:37 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.