How to add a new column to a grid? - datagrid

I have a datagrid with two columns and with two buttons inside the grid: edit and delete.
When I click on edit I want a new column to be added to the grid.
How do I this?

Use the method datagrid.Columns.Add().

As Sjoerd said, use the method but it will not have a name. You would need to add the name of the column in the method unless you edit it directly in the datagrid.

Related

How to get the selected rows in ASPxGridView?

I have a grid with ASPxCheckBox in Data Item Template. How to get KeyFieldValue of all rows whose checkbox is checked. I am trying to do this using client-side code and do it for whole grid not on visible index. Is it possible?
Note: I cannot use simple row selection command column as I am using it for some other purpose.
if you dontuse client-side code, you should use detailrow in aspxgridview. And you must use beforeperformdataselect event. if you really need checkbox, you can add checkbox a new field in asapxgridview.

make a cell as template field in GridView

I have a grid view which is dynamically populated with data. and the no.of columns may be changed each time according to the query.. i want to make the first field to select the row of data(by making it template field). I cannot declare statically the columns as template fields because the column numbers are dynamic.
can any one help how to proceed.
You need to create your own template builder - a class implementing ITemplate interface - use InstantiateIn to build your template by adding needed controls to the given template container. Add TemplateField column to the grid-view and use your class as ItemTemplate.
See this article where this is illustrated: http://www.mindfiresolutions.com/How-to-add-a-TemplateField-to-a-GridView-dynamically-841.php
Further, what you want to achieve might be possible by creating your custom DataControlField - for example, for selection column, I may use a class inherited from CheckBoxField (something like http://www.asp.net/data-access/tutorials/adding-a-gridview-column-of-checkboxes-cs)
It's a bit of work but the following article walks through all of the steps: How to create template columns dynamically in a grid view
There is no easy answer for what you're trying to do but the above link will help you if you are willing to put in the time and effort to get it done.

Editing an asp.net DropdownList

I have a dropdown list of 5 elements. My problem is that I want to make this dropdown list editable. Basically a user might want to delete one of these elements or might want to add more elements. Whats a good approach of doing that in asp.net ?
Use a ComboBox.
You have to put textbox for typing text and button for user to insert into the list and button for delete
Do you know the code to adding and deleting list in the dropdown list right ?
Use a ListBox - that way they can make a multi-selection of their choice:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listbox.aspx
The DropDownList is not intended for multi-selection. Another option would be to use CheckBoxes.
If you use DataBase, u can make dropdownlist MORE editable with elements like "formView", "gridView" and so on..

Reassign Checked rows from one GridView to another

I have a gridview that has a checkbox (inside TemplateField). I would like to grab all the selected rows and reassign them to a new gridview. Any ideas on how I can go about doing this?
Thanking you in advance.
If I understand your question, the easisest way to do it is to wrap the second grid in a separate grid. Assuming you have named the checkboxses the same id for your second grid, you can use jquery plugin to detect selection of the first grid's check boxes, loop through the results and set check boxes of your second grid inside that other div to "checked" since the names of the chck boxes match.
Something like that:
$(document).ready(function () {
$('#BaseDiv > input[name=checkboxlist]:checked').each(function() {
//TODO: Retrieve the checkboxes from the second div using the combination of second div id and search for it's children check boxes.
});
});
just fetch all the checked rows from the first gridview and add them into a datatable. Now assign this datatable to another gridview as datasource and bind it.

Grid View Generic Functions

currently I am using few generic functions/methods in gridview for Sorting Images and Getting Header Row in TH and merge Header Row.
Link
http://marss.co.ua/MergingGridViewHeaderColumns.aspx
problem is i have to write these function for every Grid. I looking for solution, Where I can define these behaviors only at one place.
Create an object that inherits from the GridView. Add your properties and functionality to that new object. On your page add that new object instead of the GridView. And if you go totally nuts like I did, you can end up creating a totally different control. See the
GridViewTree.

Resources