Reassign Checked rows from one GridView to another - asp.net

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.

Related

Insert New Row In GridView Footer At Button Click at Run Time

I just want to insert A new row in gridView Footer On button click, which is out side Of gridview. every time user click On button There is New row will be inserted In gridview footer for data entry with text box. GridView data row shows the data from database and in footer row which contain text box For new entry. user can add more than one Footer row with text box on by clicking on the button.
Please help me...
Thanks...
We had a similar situation, however we were adding rows dynamically to the body of the table. No reason a similar approach wouldn't work. Note that if you need to submit this data back to the server then some additional functionality needs to be implemented.
Some code is below.
$('button').click(function () {
var newRow = $('table tfoot').First('.Row').clone(); // If you need to insert dynamically you can create the elements in code
$('table tfoot').append(newRow);
});

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.

select multiple gridview rows with Ctrl+Click?

Is it possible to select multiple gridview rows using Ctrl+Click and then delete all the selected rows with a button?
You can have a hidden field on the page that gets updated with each row ID in some sort of delimited list. Using jQuery, you can easily add a click event to each row that will add the ID to the hidden field on the client. After clicking a bunch of rows, the hidden field might look something like "3,65,245,111"
Here is a bit of jQuery to get you started. This will assign a click event to each row of a table with the ID "myTable":
$(document).ready(function() {
$('#myTable tr').click(function() {
//Insert your code to handle the click event and assign the row value to your hidden textbox
});
});
The above will make it so that you can handle each time a row is clicked. You'll need to write a bit of code and be creative to figure out how to get the ID of the clicked row.
A separate "delete all rows" button would take the value in the hidden field, split the string at each comma and then delete each row one at a time.
There are lots of different ways to skin this cat and the above is a quick and simple way to get the job done.

Adding a new row in between rows in a grid view

I have an ASP .net grid view. It has some template columns like a command button, a text box, and a dropdown control. When I click the command button, a new row needs to be inserted below the current row (from where I hit the command button).
If I have rows 1 and 2 and I hit the command button in row1 a new row needs to be inserted between rows 1 and 2
Now in the new row I should be able to select values from dropdown and enter some value in a text box and finally hit my save button. (Which should work fine as I am expecting)
The grid view is bound to some data source say for instance a datatable for now.
Oneway that I could think about is when Command button is clicked, I can add a new row to the datatable in my server side code and rebind the grid. But I am not sure that, from a UI perspective how I can make sure that the new row goes exactly below the row from where I hit the command button.
Any thoughts or comments?
I think a much easier approach will be if you try to add the row in your data source and then bind to the GridView again. This is easy if you have DataSet or a custom entity collection. Since, you are using DataTable this will also work. Handle the click event and find the row that the user clicked. Go back to the dataTable and add an empty row there. This will make sure that the controls inside the GridView are persisted and you don't have to worry about adding DropDown controls etc.
You have to sort the datasource by an virtual index saved in an invisible column. On first databound(perhaps you take a DataView because of ots sorting capability) it will set to the original rowindex. After first hit of the save button you get the datatable again from database and add the additional row with an index after the "selected" row. Then you bind the GridView again with the sorted DataView.
I think you need another invisible column to detect the "temporary" row. If you dont need to edit the "normal" rows then you can use edititemtemplate for this. Otherwise you can make the dropdown and textbox visible and the other controls invisible in GridView.OnRoawDataBound.
There is a code sample that is used for adding a new row in between rows in a grid view.

how to make an checkboxlist select only one item selected

i am using an checkboslist binding to a datatable.
but here i need to make user select only one item selected from checkbox list
is there way we can aachive this
either JQuery, javascript, c#
thank you
If the user is only allowed to select one item from a list, you should use radio buttons instead of checkboxes.
UPDATE:
If you have to use checkboxes then you can use the following code:
$("#myform :checkbox").click(function(){
$("#myform input:checked").attr("checked","");
$(this).attr("checked","checked");
});

Resources