I'm adding items dynamically when a row is selected from GridView.
1. How can i make the items added are selected by default - (solved)
2. How can i avoid duplicates getting added to list
3. How can i remove them from list when user un-checks them.
And I want to change checkbox with an image and I'm using css like following but it is not working
.cbxCustom
{
...
}
.cbxCustom tr td checkbox
{
....
}
<asp:CheckBoxList ID="cbl1" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="cbl1_OnSelectedIndexChange"
CssClass="cbxCustom">
</asp:CheckBoxList>
Duplicates can be avoided by keeping your items in a List and before adding the item, check to see if lst.Contains(itemName). If it does, don't add it.
Removing them from the list is a little more problematic because it depends on how deeply you want to go into it. I'm assuming you don't want a PostBack for each click of a checkbox. If you want a PostBack, you'll need a way of serializing your list of checkboxes and information into a control in the ViewState. Since you're dynamically adding this list in the code-behind, I'd recommend an invisible Literal whose job is just to hold a serialized string holding your data.
If you DON'T want a PostBack, you'll need to work up a significant amount of JavaScript to modify the InnerHTML of the table that is output by the CheckBoxList. Again, as above, I'd use a Literal or some ViewState managed invisible control to serialize the state. In this case a literal wouldn't work, but a might.
Related
I have a gridview of everything inside a table. I wanted to create a filter for it to allow users to narrow down the gridview. I have 2 listbox. List box 1 holds all the filters, then you can move the filter you want to the 2nd listbox. then when you apply the filters it only applies the filters in the 2nd listbox. When you select one of the filters in the right I want it to display the filter properties to fill out to use in the query for pulling back the gridview.
Is there a way to have the panel show when you select a value in the 2nd filter? I guess im not sure if there is a function to allow me to do this?
Here is how I was trying to get it to look like http://i.imgur.com/neWYftY.jpg
Thanks for any suggestions.
Make the panel invisible on initialization:
<asp:Panel ID="Panel1" runat="server" Visible="false">
Then make it visible in the event handler for the autopostback filter selection:
Panel1.Visible = true;
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
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.
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
I have a datalist inside a usercontrol that gets loaded into a page where users can customize a report based on some checkboxes.
One of the checkboxes, however, is "Hide Worklog" which should hide the worklog column from the result set because it can be quite long and interfere with the report.
If I do:
datatable1.Columns.Remove("WorkLog");
the code throws an exception because:
<asp:Label ID="WorkLog" runat="server" Text='<%# Bind("WorkLog") %>'></asp:Label></td>
doesn't exist.
Am I going about the usercontrol all wrong? This usercontrol should always be able to show the worklog, so I don't think it's bad to bind it in there, but at the same time I want to be able to hide it if the user wants.
Try removing the label control from your DataList instead of removing the column from the data source (i.e. the DataTable)
DataList1.Controls.Remove(DataList1.FindControl("WorkLog"));
You shouldn't get an error if the data source has more columns than you're displaying on the page, however, you will get an error, as you've discovered, if you're trying to display a column that doesn't exist in the data source.
bind it in code behind after checking some condition. like
if (visible) {
//bind
}
while removing control
visible = false;
you might need to change visible to session var :)