|
Subject:
|
Creating Dynamic Forms with ASP.NET
|
|
Posted By:
|
saturdave
|
Post Date:
|
2/6/2004 3:20:38 PM
|
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?
|
|
Reply By:
|
katsarosj
|
Reply Date:
|
2/7/2004 12:25:13 AM
|
Check out this thread:
http://p2p.wrox.com/topic.asp?TOPIC_ID=5517& SearchTerms=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
|
|
Reply By:
|
planoie
|
Reply Date:
|
2/9/2004 11:09:08 AM
|
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/default.asp?url=/library/en-us/vbcon/html/vbconintroductiontodatalistwebcontrol.asp
Peter ------------------------------------------------------ Work smarter, not harder.
|
|
Reply By:
|
saturdave
|
Reply Date:
|
2/9/2004 11:58:02 AM
|
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.
|
|
Reply By:
|
dsg
|
Reply Date:
|
11/23/2004 5:38:48 AM
|
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
|
|
Reply By:
|
planoie
|
Reply Date:
|
11/23/2004 5:10:54 PM
|
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.
|