Grouping Controls ASP.NET - asp.net

I have a question. Let's say I had a number of controls which when I click "Add" the same group of controls would display again.
For example my grouped controls would look like this:
First Name: TEXTBOX
Last Name: TEXTBOX
ADD
When ADD is clicked an additional 2 textboxes appear. So on my page I'd have the following:
First Name: Someones Name
Last Name: Someones last name
First Name: TEXTBOX
Last Name: TEXTBOX
ADD
And so on....
Is there a control (multiview, etc) I could use to do this?
Many thanks in advance,
Jason

I would recommend using a UserControl. You can create them programmatically.

My favorite control in this scenario is the ListView, which allows you to define templates for regular items and the insert row.
Here is multi-part demo on the list view that will show you how it's done.
https://web.archive.org/web/20211020150712/https://www.4guysfromrolla.com/articles/010208-1.aspx
The control is especially effective if you are data binding to a data source, which can be a database or .NET objects. Although not directly applicable to the ListView, you may find this resource helpful, as it describes different uses for Data Sources:
http://msdn.microsoft.com/en-us/magazine/cc163862.aspx

The only way built-in is to use a listview control (or other repeating control) and set it up something like the following: http://mattberseth.com/blog/2008/05/bulk_inserting_data_with_the_l.html
Everytime add is clicked, you have to create a new object from the underlying data source that's blank and rebind the new data source in the listview or other control...
Otherwise, a custom/user control with programmatic creation would get the job done.

Related

Appropriate ASP.NET control to display detailed information of a record

This is a example of what I am trying to archive
(source: http://store.apple.com/us/product/H7537LL/A/)
I need to display data (mostly text, also have picture and files) from database to a webpage (this could be a product information or a job description or something like that...), what the the appropriate control that developer often use I can use to archive this.
When inserting text (multi-lines) from a textbox to database table, HTML is not allowed so when I pull data out to display them again to the webpage, the break line characters were lost all I get is bunch of text without line break.
I am having a hard time to find the way to save and retrieve, display data, any advices or comments are appreciated.
As per your requirement you can use asp.net Repeater control
Please refer this LINK for more detail about Repeater control
The Repeater control is useful if you need a high degree of control over the generated HTML. Also see the DetailsView control. Here is MSDN documentation describing these controls.
Repeater
The Repeater control is a data-bound container control that produces a
list of individual items. You define the layout of individual items on
a web page using templates. When the page runs, the control repeats
the layout for each item in the data source. For information about
programming the Repeater control, see Repeater Class in the MSDN
library.
DetailsView
The DetailsView control gives you the ability to display, edit,
insert, or delete a single record at a time from its associated data
source. The DetailsView control displays only a single data record at
a time, even if its data source exposes multiple records. For
information about programming the DetailsView control, see DetailsView
Class in the MSDN library.
I'm adding a second answer based on your edited question.
The page like the Apple one you linked to (if it were written in ASP.NET) would be comprised of many different controls, so there isn't any one control that's going to work well for this situation. You're going to end up needing to create an entire page. For that, the only suggestion is to study basic ASP.NET Web Forms to create your page, then load the production information based on the product specified in the URL.

ASP.NET Design Issue: what is the best asp.net control for creating a table with 15 properties?

I am a new ASP.NET developer and now I need to develop a data entry system with 15 fields that allow the admin of the system to enter some data under each one of these 15 properties. From what I learned in ASP.NET tutorial, I think the best control is the ListView control in order to give the admin of the system to enter a new field if he wants in the future. My problem now is the following:
How to divide these 15 fields into two columns? Because all what I see about using ListView is putting all of the properties at the first row and the entries will be underneath of them. What I want is to create a list with two columns of properties and two columns for the entries
I'm not sure that a ListView makes sense from your description. Are your administrators updating the same properties on different objects? Like most of the ASP.NET controls in its class -- the Repeater and GridView are other similar examples -- the ListView is meant to create several rows of identical information based on an HTML template you provide.
If your administrators are creating or updating:
The same property for different objects, then the ListView, Repeater, or GridView would be fine.
Different properties for the same or different objects, then you need a more traditional form with normal data entry controls (like the TextBox, HtmlSelect or DropDownList, CheckBox, etc.)
I would use a more liberate approach and code the fields my self into the view you'd like.
At first it might take more time, but after that your would be able to control the look of it much quicker and easily.
Using a listView you can build your edit/input gui as you'd like - a table or any other way. If really must divide into 2 columns - you could just put a label and then the field just underneath it. 7 on one side and 8 on the other.
If you're looking to use the edit features of a data control, you could create a custom item template for your data control (be it a gridview or whatnot) that has a table and each of the properties (I assume all 15 are conisidered 1 row of data). Bind your single row to the data control and it should work. You could even have different template views for display and editing using the templates.

ASP.Net, how to put hyperlinks in datagrids.

Hi i have a datagrid I've put in on a aspx web form in visual studio 2010, I'm new to this so I've been following the ms tutorials.
One of the columns on my data grid contains a lot of information, is there a way i can add a "+more" option in the cell next to the entry that shows only the first few characters of that cell, but once clicked opens all the information on that particular entry but onto a new aspx form?
Thanks for any help!!
There are basically three different ways...
Structure your data object/query so that it returns a key and and abbreviation (i.e, first name, last name, id, bio) and use a template that turns id into a link.
Use the onrowbound event to manipulate the controls on the row, so that you have a href to your details page.
Use css to show the additional info on a hover/mouse over (I like this, but it doesn't play well with mobile devices, which don't have either event).
EDIT: Methods 1&3 would be done on your aspx page, method 2 would be done in the codebehind for your page. Method 1 is really dependent upon your being able to control the data object/ query results. If you are calling a stored proc that someone else controls, it may be very difficult to make it work.

Problem With Multiple Data Bindings (Silverlight)

I am using silverlight to create an Intranet for managing chemical usage. All data is stored in a MS SQL database, and is retrieved by using a DomainService (RIA).
By dragging the database onto the form, Silverlight has created a DomainDataSource based on this table. By then creating a new record using the following code, I am now able to add new records.
Me.ChemicalApplicationDomainDataSource.DataView.Add(chemicalApplication)
However one of the controls I have on the screen is an AutoCompleteBox. I have bound this to the database, and the values display fine on here. When an item is selected on here, I want to populate the value of a textbox with values retrieved from a second datatable.
I have created an event on the AutoSelectedItemChanged, and added the following code:
Context.Load(Context.GetChemicalByNameQuery(AutoMaterialTradeName.Text))
I can then bind this to a datagrid.ItemsSource, and it shows the relevent record. But I cannot for the life of me get it to bind to a textbox. Textboxes dont have an ItemsSource, only a DataContext, but binding to this does not seem to display anything..
Any tips on how to achieve this?
You would need to bind it to the Text property on the TextBox for that to work. Additionally you would probably need to set the Path property on the binding to get the right property on your object to display.

ASP.NET - Hierarchical grid view

Any ideas on how I can acheive 'Hierarchical' gridview?
Basically I want when the user clicks on the '+', i "expand" and insert new rows without a full page post back.
Does this sound like a lot of AJAX stuff? Or should I read on ASP.NET MVC
Please point me in right direction
Another way to do this is the old Grid view inside a Grid view Trick. The basic concept is to have the [+] and the parent data as the Item data in a single templated column. Attach the to click event of the button and set your grid to edit/selected mode. when its in edit mode, render a second grid view with the child data. Although its a gridview inside a gridview, visually it will accomplish a "hierarchical" view.
Sample source code for Hierarchical GridView
with [-] and [+] to collapse and expand as in VB6 Hierarchical Grid
You have two options I suppose:
You can render out those rows you want to insert, and the [+] shows them and hides them
You don't render them out, and they are sent to the browser via AJAX, and then inserted into the table.
I've done it both ways, and the more gridviewy way to do it is the first, in my opinion. You can create a new templatefield for the [+]; define a child relationship name, and then call GetChildRows (or an equivalent) on each row as you render, having those rows render hidden.
#bnkdev - GridView inside a GridView sounds like a total mess.
#Jandwenyi - I suppose you're doing this for a certain scenario and you'll need to reuse it at some point, as unprobable as it may seem now. My suggestion - find a third-party Grid control that would do what you want - there are so many out there.

Resources