473,568 Members | 2,939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Dynamic" form -- how to?

Here's what I'm trying to accomplish: I get a number from another page
that indicates the number of members.

The page I want to build -- actually it's not a page, but a UserControl
-- needs to display a form with several types of input fields for each
of those members: regular text fields, a dropdown and Infragistics'
WebDateChooser.

The point is that someone inputs thinsg like name, date of birth etc
for each of the members, which is then submitted to the database.

I was thinking of constructing a DataSet and binding that with a
DataGrid, like this:

--ASCX----------------------------------------------------------------

<asp:DataGrid ID="dgMemberLis t" Runat="server"
Width="100%"></asp:DataGrid>

--CODE-BEHIND---------------------------------------------------------

DataTable oDT = new DataTable( "MLDT" );

oDT.Columns.Add ( "LastName" , typeof( System.String ) );
oDT.Columns.Add ( "FirstName" , typeof( System.String ) );
oDT.Columns.Add ( "DateOfBirt h" , typeof( System.DateTime ) );
oDT.Columns.Add ( "Nationalit y" , typeof( System.Int32 ) );
oDT.Columns.Add ( "Gender" , typeof( System.String ) );

for ( int i = 1 ; i <= iNumberOfMember s ; i++ )
{
DataRow oDataRow;
oDataRow = oDT.NewRow();
oDT.Rows.Add( oDataRow );
}

DataSet oDS = new DataSet( "MLDS" );
oDS.Tables.Add( oDT );

dgMemberList.Da taSource = oDS;
dgMemberList.Da taMember = "MLDT";
dgMemberList.Da taBind();

--END-----------------------------------------------------------------

And then adding the controls, of course. Plus: I also need to check
what they input, preferably via RequiredFieldVa lidator and the likes.

But I'm now wondering about the wisdom of that decision, partly since
I'm kinda stuck at the moment. Does anybody have a better idea?

(FYI: This is all in asp.net/c#, made with VisualStudio.NE T.)

--
BVH

Mar 10 '06 #1
3 1427
A DataGrid seems like the right choice to me.

You didn't mention *why* you're stuck ... which is a something of an
impediment to further advice ... :-)
Brett.

Mar 10 '06 #2

Brett Wiltshire wrote:
A DataGrid seems like the right choice to me.

You didn't mention *why* you're stuck ... which is a something of an
impediment to further advice ... :-)


Yeah, I was just wondering if anyone had ever done such a thing and
what their experiences were.

However, I've now run into several problems. Here's how I'm now doing
the datagrid:

<asp:datagrid id="dgMemberLis t" runat="server"
AutoGenerateCol umns="False" Width="100%">
<Columns>

<asp:TemplateCo lumn HeaderText="Las t Name">
<ItemTemplate >
<asp:TextBox runat="server" id="txtLastName " Text='' />
<asp:RequiredFi eldValidator id="rfLastName "
ControlToValida te="txtLastName " Text="The last name field is required!"
runat="server" Display="None" EnableClientScr ipt="false" />
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="Gen der">
<ItemTemplate >
<asp:DropDownLi st id="ddGender"
runat="server"> </asp:DropDownLis t>
<asp:RequiredFi eldValidator id="rfGender"
ControlToValida te="ddGender" Text="The Gender field is required!"
runat="server" Display="None" EnableClientScr ipt="false" />
</ItemTemplate>
</asp:TemplateCol umn>

</Columns>
</asp:datagrid>

<asp:Button id="cmdSubmit" Text=" Continue " runat="server" />

<asp:Validation Summary id="lblSummary " runat="server"
ShowMessageBox= "false" HeaderText="Err ors are as
follows:"></asp:ValidationS ummary>

1. I want to populate ddGender with data from the database (*), however
when I tried to it didn't work:

ddGender.Items. Insert(0, new ListItem( "Male" , "1" ) );
ddGender.Items. Insert(0, new ListItem( "Female" , "2" ) );

Result: " System.NullRefe renceException: Object reference not set to an
instance of an object." I'm guessing that I need to loop through the
Items collection of the DataGrid and access each filed that way?

(*) Yes I know that this is silly when it comes to gender, but there
are other fields like nationality that do come from the database, and
anyway I do need to fill ddGender with data.

2. When I click the submit button, I do get to see the title of the
lblSummary, but no actual errors. I'm guessing that a similar problem
is happening here: the RequiredFieldVa lidator cannot find the control
it is supposed to check?

Reason I'm not debugging with VisualStudio: I'm at home and I don't
have VS installed here.

--
BVH

Mar 11 '06 #3
Sorry for the delay in responding...pe rhaps you already have the
solution, which is great, but if not then this may help.

Your best bet is to implement databinding for your dropdowns and let
the datagrid deal with populating the values for each instance. This
is what I have done here. Notice the DataSource property. This refers
to a public property of my code-behind class that exposes, in this
instance, a DataSet. I'm fetching the dataset from a database, but
naturally you could build this up with code if you wish.

....
<ItemTemplate >
....
</ItemTemplate
<EditItemTempla te>
<asp:DropDownLi st
id=ddAnalysts
style="VISIBILI TY: visible"
runat="server"
DataValueField= "UserId"
DataTextField=" FullName"
DataSource="<%# AllUsers %>"
DESIGNTIMEDRAGD ROP="2095"
SelectedValue=' <%# DataBinder.Eval (Container,
"DataItem.Analy stUserId") %>'
</asp:DropDownLis t> <asp:Label
id=lblAnalystNa me
style="VISIBILI TY: visible"
runat="server"
Text='<%# DataBinder.Eval (Container, "DataItem.FullN ame") %>'</asp:Label> </EditItemTemplat e>
....
As for the field validation:

....
<EditItemTempla te>
<asp:TextBox
id=txtDisplayOr der
runat="server"
Text='<%# DataBinder.Eval (Container, "DataItem.Displ ayOrder") %>'</asp:TextBox> <asp:RegularExp ressionValidato r
id="RegularExpr essionValidator 1"
runat="server"
ValidationExpre ssion="[0-9][1-9]|[1-9][0-9]?"
ControlToValida te="txtDisplayO rder"
ErrorMessage="M ust be a whole number between 1 and 99"</asp:RegularExpr essionValidator >

</EditItemTemplat e>
....

Again I'm defining this in the EditItemTemplat e in my case. When the
framework renders the page, it will uniquely name the controls, so
there shouldn't be any problem...
I hope this helps.
Brett.

Mar 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1756
by: Michal Grabowski | last post by:
Hello, I need to have a stored procedure, which performs sorting. Something like this: CREATE PROCEDURE procname @sortby varchar(30) AS BEGIN SELECT some, columns FROM some_table
3
5470
by: Buddy Robbins | last post by:
Hey folks, I am re-writing an ASP.Net site for a company. The client wants to be responsible for the static content and navigation of their site, and I'll be responsible for any dynamic content. I'm using Infragistics Ultra Web Navigator, which can load the menus from an XML file, so the navigation requirement is taken care of. I had...
1
1568
by: Razzbar | last post by:
I'm creating a site that is all on one page. The navigation of the site is enabled by a hidden iframe that fetches content from the server and re/places it in a div on the page. The problem is how to allow visitors to bookmark "pages" when the page is dynamic. I can use Apache-style pseudo-urls to parse out the location of the dynamic...
0
1435
by: raca | last post by:
I am trying to create a generic SOA ServiceInvoker that will accept an XML string that will be used to deserialize an object generated by XSDObjectGen. The hierarchy goes like this: Requests...Request (1..n)... Payload (1)... PayloadCollection (1) ... Payload (0...n) I have the knowledge about the root object Responses which I can create...
2
2225
by: Paul E Collins | last post by:
I'm considering using the NetSpell spell checking engine in my application. However, NetSpell is licensed under the Lesser GPL, and I want to withhold my application's source code. The licence states that I can do this if I link to the NetSpell library dynamically (rather than compiling against it statically). How can I achieve this in C#?...
5
1737
by: Brad | last post by:
All samples related to this see to come short of being 'truly' dynamic. For instance, after creating all the code to load/save a properties value, you turn around and save it to one you KNOW exists: foo.Height = (my loaded value)... I am trying to load and set the property on the fly - without necessarily knowing what it is. Imagine a 100...
1
2645
by: Nathan Sokalski | last post by:
When testing a form of mine which uses RequiredFieldValidators that have the Display property set to "Dynamic" the ErrorMessage property is automatically removed when an entry is completely typed and the user leaves the textbox. However, if the entry is selected from the list of previously typed entries, the error does not disappear until the...
3
2470
by: Good Man | last post by:
Hi there Ideally, I'd like to create one javascript function and pass the file extension i'm looking for to see if its there: <input type="file" onchange="checkFile('pdf',this)" /> and then have the function something like (w/ Prototype)
0
933
by: walterbyrd | last post by:
This according to SDTimes: http://www.sdtimes.com/article/story-20071215-13.html They don't specifically mention Python. But, I think Python qualifies as a dynamic language. "1. Dynamic languages are on the rise. We went into 2007 knowing that Ruby would be a popular topic, thanks to Ruby on Rails, and that JavaScript was resurgent,...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.