Is there a textboxlist control available somewhere? - c#

There are ASP controls such as radiobuttonlist and checkboxlist and you can databind them to a database query. It's great for creating dynamic lists with user interaction. What I'm trying to do is generate a list of textboxes in the same fashion. A list of textboxes that behave the same way.
The object is to have a checkboxlist that is generated via datasource/database. When the user is finished selecting items from this list, they click a button. That list hides (using jquery) and a new list is created based on their selections. However, the new list is now a list of their selections accompanied by an empty textbox. The user fills in the textboxes for each entry and submits again which commits it to a database.
SO:
checkbox - description
checkbox - description
checkbox - description
checkbox - description
Becomes:
Description - Textbox
Description - Textbox
The reason that I'm looking for a list-type control is so that I can ultimately loop through it for submission to the database using linq. Does that make sense? My real question is if there is a control like this yet. I gave the full description in case someone has any other ideas, short of creating a custom control.

There's nothing out of the box that does what you describe no. But you can still loop through controls. I would put your form controls inside of an asp:Panel or a div with runat="server" and use something like the following code to cycle through them as you described.
foreach(Control ctl in myPanel.Controls)
{
//check control type and handle
if (ctl is TextBox)
{
//handle the control and its value here
}
}

asp:ListBox has a property named SelectionMode, which can be set to SelectionMode="Multiple" and allows you to select items you want. This is not exactly what you need but it's a simple solution.

After the selection is made in checkboxlist, make a postback to server. Here create a datatable with two columns (description & text). For every selected item in the checkboxlist add a row to this table and bind it to a gridview control. Here 'text' column will be always empty. Configure the gridview to use template column with a textbox in the itemtemplate

Related

How to pass selected list value from popup into a textbox using C# webforms?

I have a table called Vendor that has two columns: VendorNum & VendorName.
Is there a way to create a list or a listbox or a listview that when a button is clicked, this vendor list will pop up. Then the selected popup list's row will pass the selected VendorNum into a textbox that's in the parent page..
I only know GridView has the select row option, but is it a proper way to put the gridview into a Listbox so the list can be scrolled up/down all within a fixed box?
You might want to take a look at the ListBox.SelectValue and/or ListBox.SelectedItem properties

How To Hide ListView ColumnHeader?

I am struggling to figure out the correct control to use for a list of predefined jobs in the included form. I currently have a ListBoxControl in the Predefined Job Name group that lists all of the predefined jobs for a marine service shop (i.e. oil change, tune up, etc...). Then, based on the item (i.e. job name) that is selected in my ListBox, I need to display the items that correspond to that job. For example, if oil change is the selected job I need to show 4 quarts oil, 1 oil filter, labor, etc...and so on.
Currently, when I load the form data I have a DAO that retrieves all of my jobs from the database using LINQ to SQL. Then I iterate over the results and put the job names into the ListBox. The problem that I am having is that there is no tag for ListBox items like there is for ListView items. So each time the user selects another item in the ListBox, I have to perform another LINQ query to get the job from the database again so that I can display its' corresponding items. If I could use a ListView and hide the column header I could set the entire job on the tag so that each time the user selects a new item I would have access to the details without having to make another call to the database. Is there a way that I can hide the column header of a ListView without hiding the entire column?
You can set the HeaderStyle member of the ListView to None.
listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
Checkout the ListView HeaderStyle property. It has the following options:
None
Nonclickable
Clickable
From MSDN:
The HeaderStyle property allows you to specify whether the column headers are visible or, if they are visible, whether they will function as clickable buttons. If the HeaderStyle property is set to ColumnHeaderStyle.None, the column headers are not displayed, although the items and subitems of the ListView control are still arranged in columns
You can also create simple object like ListItem which has two poperties: Text (string) and Tag (object). Then implement ListItem.ToString() and you can use these in the ListBox as well.
You can also check out Better ListView Express component, which is free and allows displaying items in Details view without columns. The advantage over ListBox and ListView is a native look and many extra features.
Easy way is using the ColumnWidthChanging event
private void listViewExtended1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
if (e.ColumnIndex == 0)
{
e.Cancel = true;
e.NewWidth = listViewExtended1.Columns[e.ColumnIndex].Width;
}
}
I found that if you know for a fact you are not displaying the headers it may be best to set the HeaderStyle property to None, as Rajesh mentions above.
When setting in the .CS when screen initially loads the headers are displayed until screen is fully rendered.

Editable GridView Distinct Drop Down LIsts

I have a simple app I am messing around with its a basic Master/Details layout.
The details panel is actually a tab panel and on one of the tab panels it has a GridView. Within that grid view it shows the "current" in database information with all cells as read only.
alt text http://lh4.ggpht.com/_JU1W2P96pD4/TAeonNNYXgI/AAAAAAAAAq0/Y_-Kse7VObE/ExampleA.jpg
I then have an add button that inserts a row into the GriView and allows the user to enter some information. The first item in my GridView is a DropDownList, which is populated from an ObjectDataSource. This drop down is basically my unique index and there can only be one selected value per GridView.
alt text http://lh3.ggpht.com/_JU1W2P96pD4/TAeonIF3DdI/AAAAAAAAAq4/JhfOTsHgsf8/ExampleWithDropDown.png
What is the best way to remove the values from the list that are already in the GridView? Do I just need to remove the data source and add a OnDataBinding method that iterates through the grid view and generates a valid list of values?
I can't use a service method because if the user adds two rows they would have the option to insert duplicates description types.
Just want to make sure there is not a better way to do this.
Keep the object datasource, which I am assuming is an IEnumerable object, in a Session variable. When someone selects a certain value remove that value from the list in the session variable. Whenever they activate the form where the drop down list is displayed simply rebind the control to the list in the session variable. It will be easier than looping through the grid every time the user adds an entry.

Display ASP.NET GridView inside a selected row in another GridView

I have been given a mockup that I do not know is possible to code in ASP.NET without being a real html and javascript wizard.
I want a GridView that when a row is selected, the selected row expands and below the selected row a panel of additional information is shown, which would also include another small GridView. The idea is this would all be in-line. So if the user selected row 4, then the additional information would appear below row 4 and then after the additional information the parent GridView would continue with row 5.
Ultimately I would want to do a multi-select type of set up, but first I need to figure out if this is even possible. Also, the solution must be 508 Compliant
The one solution I considered was using only one "column". Then I would put all my fields in the ItemTemplate, and my detail panel content in the EditItemTemplate and instead of selecting the row, set it to edit mode. The problem with this solution is I lose the functionality of multiple columns if I throw everything in one huge ItemTemplate.
Any and all suggestions or ideas are appreciated.
What you're describing would be best fulfilled with a ListView control. It takes a little more templating work to set up than a grid view, but you have much more control over it and you can emulate the look of a GridView. You would set your Selected Item template to contain another ListView (or GridView) thats bound to your detailed data.
I've done this using a gridview inside a ListView and using ajaxcontroltoolkit collapsible panel
Your parent list would be a listview that would have 2 table rows for each item, on the first row your parent column, on the second row use colspan and add a gridview wrapped on a collapsible panel

Adding rows to a table based on user input (ASP.NEt)

I have a TextBox entry field where the user will enter a integer value. And then there is a "Create" button, which when clicked upon must generate a Table with 2 columns :
"Name" and "Email" being the column headers.
I want each row to have a textbox in each of these columns.
All of this has to happen after the button is clicked. I have discovered that if you dynamically add a control in ASP.NET(I am using C#) then the controls are lost during postback. And I don't know how to prevent that from happening.
Can somebody please give me some ideas regarding how to go about adding rows dynamically to a table (I tried using the asp.net Server side table control but ran into the "lost-during-postback" problem - can I try with something else like a gridview ? but afaik a GV will not work without data bound to it )
Point to note is that my table has textboxes for user entry and it is not for showing data ..rather it is for accepting data from the user which will be later used to persist details to the database.
Dynamic Controls
That's involved. Here's an interesting article on the issue of dynamic controls.
I think normally if you create dynamic controls then you're responsible for recreating them on postback; however the article contains a way to use the Init event if it's copacetic with your app.
Edit:
or Regular ASP.NET Controls
You can use data bound ASP.NET controls like: DataList, Repeater, GridView, etc. (You can put text boxes and all other kinds of controls into them for repeating in each row - or "item") and bind values to it. If you need to perform some processing on the user input first, then generate an internal Array, List, Dictionary, DataTable etc. (your choice) and bind that data as a data source to the ASP.NET control of choice.
aspnetControl.DataSource = myDataTable;
aspnetControl.DataBind();
or
aspnetControl.DataSourceId = "name_of_control";
There are various ways to assign a data source.
This way you won't run into the same problems as with dynamic control creation; however there is a lot to learn to facilitate this way too.

Categories

Resources