Hi!
I need some help. I need to copy checked records from grid1 to grid2, by clicking a button. Grid1 has allowpagination = true.
I have problems when I change page, cause I lose records selected on another pages.
Also I need to copy to Grid2 selected records in other pages, not the actual page.
Thanks in advance.
<script type = "text/javascript">
function Check_Click(objRef) {
//Get the Row based on checkbox
var row = objRef.parentNode.parentNode;
//Get the reference of GridView
var GridView = row.parentNode;
//Get all input elements in Gridview
var inputList = GridView.getElementsByTagName("input");
for (var i = 0; i < inputList.length; i++) {
//The First element is the Header Checkbox
var headerCheckBox = inputList[0];
//Based on all or none checkboxes
//are checked check/uncheck Header Checkbox
var checked = true;
if (inputList[i].type == "checkbox" && inputList[i] != headerCheckBox) {
if (!inputList[i].checked) {
checked = false;
break;
}
}
}
headerCheckBox.checked = checked;
}
function checkAll(objRef) {
var GridView = objRef.parentNode.parentNode.parentNode;
var inputList = GridView.getElementsByTagName("input");
for (var i = 0; i < inputList.length; i++) {
var row = inputList[i].parentNode.parentNode;
if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
if (objRef.checked) {
inputList[i].checked = true;
}
else {
if (row.rowIndex % 2 == 0) {
row.style.backgroundColor = "#C2D69B";
}
else {
row.style.backgroundColor = "white";
}
inputList[i].checked = false;
}
}
}
}
function ConfirmDelete() {
var count = document.getElementById("<%=hfCount.ClientID %>").value;
var gv = document.getElementById("<%=gvNomenCursos.ClientID%>");
var chk = gv.getElementsByTagName("input");
for (var i = 0; i < chk.length; i++) {
if (chk[i].checked && chk[i].id.indexOf("chkAll") == -1) {
count++;
}
}
if (count == 0) {
alert("No seleccionaste ningún registro");
return false;
}
else {
return confirm("Vas a procesar los registros seleccionados");
}
}
</script>
<asp:GridView ID="gvNomenCursos" runat="server" AutoGenerateColumns="False" DataKeyNames="Cod_Curso"
AllowPaging="True" GridLines="Both" HorizontalAlign="Center" OnPageIndexChanging="gvNomenCursos_PageIndexChanging"
EmptyDataText="No se han encontrado resultados." PageSize="10" CssClass="table table-striped table-bordered">
<Columns>
<asp:TemplateField HeaderStyle-Width="35px">
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" onclick = "checkAll(this);"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSeleccionar" runat="server" class="checkbox" CssClass="span1" onclick = "Check_Click(this)"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Cod_Curso" HeaderText="Cod Curso" />
<asp:BoundField DataField="Cod_Curso_ABC" HeaderText="Cod ABC" />
<asp:BoundField DataField="Descripcion" HeaderText="Descripción" />
</Columns>
</asp:GridView>
<asp:Panel ID="panelSeleccionar" CssClass="panel" runat="server">
<div class="modal-footer">
<div class="pull-left">
<asp:LinkButton ID="btnSeleccionarActualizar" runat="server" Text="Seleccionar para Actualizar" OnClientClick = "return ConfirmDelete();"
OnClick="btnSeleccionarActualizar_OnClick" CssClass="btn btnAgregar" CausesValidation="false">
<i class="icon-check icon-white"></i> Seleccionar para Actualizar
</asp:LinkButton>
</div>
</div>
</asp:Panel>
<asp:GridView ID="gvNomenActualiza" runat="server" AutoGenerateColumns="False" DataKeyNames="Cod_Curso"
GridLines="Both" HorizontalAlign="Center" EmptyDataText="No se han encontrado resultados." PageSize="10" CssClass="table table-striped table-bordered">
<Columns>
<asp:BoundField DataField="Cod_Curso" HeaderText="Cod Curso" />
<asp:BoundField DataField="Cod_Curso_ABC" HeaderText="Cod ABC" />
<asp:BoundField DataField="Descripcion" HeaderText="Descripción" />
</Columns>
</asp:GridView>