alfinete
Power Member
code ascx
code c#
isto funciona tdo na perfeição expeto quando descomento a linha a vermelho
do tipo
isto mostra uma grid com dados em que ao checarmos um e mudarmos de pagina de mesma e ,voltarmos a traz ele mantem checkado, a linha que esta a vermelho serve para utilizar o javascript e checar e deschecar tdos ao seleccionar e desceleccionar a check do header, ou seja é esta ultima questão que não funciona
no caso de eu tirar o code que guarda os checks e utilizar apenas o que faz check all ele ja funciona para o check all
ou seja
so funciona ou para um ou para outro
eu gostava que funciona-se com as duas funcionalidades
gstava de um help
Código:
<%@ Control Language="C#" AutoEventWireup="true" Codebehind="wucEnbGridPagingTeste.ascx.cs"
Inherits="StepAhead.Web.EnbOffices.ENBOfficesWUControl.wucEnbGridPagingTeste" %>
<script language="javascript" type="text/javascript">
function SelectAll(id)
{
//get reference of GridView control
// ctl00_Contentescola_grvescolas
var grid = document.getElementById("ctl00_ContentPlaceHolder1_WucEnbGridPagingTeste1_grvteste");
var cell;
if (grid.rows.length > 0)
{
//loop starts from 1. rows[0] points to the header.
for (i=1; i<grid.rows.length; i++)
{
//dar a referencia da 1ª coluna
cell = grid.rows[i].cells[0];
//loop according to the number of childNodes in the cell
for (j=0; j<cell.childNodes.length; j++)
{
//se tipod e no filho é checkbox
if (cell.childNodes[j].type =="checkbox")
{
//atribuir o estatuto da caixa Selecionar tudo para a checkbox dentro da grid
cell.childNodes[j].checked = document.getElementById(id).checked;
}
}
}
}
}
</script>
<table runat="server" id="tblGV" cellpadding="0" cellspacing="1" width="100%" class="SACTable"
border="0">
<tr>
<td class="SACGridViewMenuTitle" colspan="3">
<asp:Label runat="server" ID="lblTitle">teste</asp:Label></td>
</tr>
<tr>
<td class="SACGridViewMenuTitle">
Coluna <asp:DropDownList ID="ddlFilterName" runat="server" CssClass="SACDDL">
</asp:DropDownList>
</td>
<td class="SACGridViewMenuTitle">
<asp:TextBox ID="txtFilter" runat="server" Width="280px" CssClass="SACTextbox"></asp:TextBox>
</td>
<td class="SACGridViewMenuTitle">
<asp:Button ID="btnFilter" runat="server" Text="Filtrar" CssClass="SACButton" /><br />
</td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="grvteste" runat="server" AllowPaging="True" PageSize="5" BackColor="#779F01"
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
AutoGenerateColumns="False" Width="640px" OnRowCommand="grvteste_RowCommand"
OnPageIndexChanging="grvteste_PageIndexChanging" OnRowDataBound="grvteste_RowDataBound"
DataKeyNames="EnbCorpoId">
<Columns>
<asp:TemplateField HeaderText="Select_All">
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" Text="SelectAll" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField FooterText="ID" HeaderText="Id" DataField="EnbCorpoId">
<ControlStyle Width="150px" />
<ItemStyle Width="150px" />
<HeaderStyle Width="150px" />
<FooterStyle Width="150px" />
</asp:BoundField>
<asp:BoundField FooterText="Nome" HeaderText="Nome" DataField="Nome">
<ControlStyle Width="600px" />
<ItemStyle Width="600px" />
<HeaderStyle Width="600px" />
<FooterStyle Width="600px" />
</asp:BoundField>
<asp:BoundField FooterText="Código" HeaderText="Código" DataField="Codigo">
<ControlStyle Width="40px" />
<ItemStyle CssClass="trat" Width="40px" />
<HeaderStyle Width="40px" />
<FooterStyle Width="40px" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="White" ForeColor="Black" />
<SelectedRowStyle BackColor="yellow" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="White" HorizontalAlign="Center" Font-Size="Medium" />
<HeaderStyle BackColor="#779F01" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:HiddenField ID="Hdteste" runat="server" />
</td>
</tr>
<tr>
<td align="center" colspan="3">
<asp:Button runat="server" ID="btnCloseWindow" OnClientClick="Javascript:window.close();"
CssClass="SACButton" Text="Fechar Janela" />
</td>
</tr>
</table>
code c#
Código:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
namespace StepAhead.Web.EnbOffices.ENBOfficesWUControl
{
public partial class wucEnbGridPagingTeste : System.Web.UI.UserControl
{
List<string> lista = new List<string>();
List<string> listaid = new List<string>();
private int n_IdAll = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
loaddados();
}
}
protected void grvteste_RowCommand(object sender, GridViewCommandEventArgs e)
{
// ArrayList arList = new ArrayList();
// string newKeyName = "EnbCorpoId";
// foreach (string dkn in grvteste.DataKeyNames)
// {
// arList.Add(dkn);
// }
// arList.Add(newKeyName);
// grvteste.DataKeyNames = (string[])arList.ToArray(typeof(string));
}
protected void grvteste_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
string[] arrIDs = this.Hdteste.Value.Split(new char[] { '|' });
foreach (GridViewRow row in grvteste.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chk1");
string ID = string.Empty;
if (cb.Checked)
{
// this.GridView1.DataKeys[this.GridView1.SelectedRow.RowIndex].Values[1].ToString();
ID = grvteste.DataKeys[row.RowIndex].Value.ToString();
if (Array.IndexOf(arrIDs, ID) == -1)
{
this.Hdteste.Value += ID + "|";
}
}
else
{
ID = grvteste.DataKeys[row.RowIndex].Value.ToString();
if (Array.IndexOf(arrIDs, ID) != -1)
{
this.Hdteste.Value = this.Hdteste.Value.Replace(ID + "|", "");
}
}
}
grvteste.PageIndex = e.NewPageIndex;
loaddados();
}
protected void grvteste_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
[B][COLOR=Red]//((CheckBox)e.Row.FindControl("chkSelectAll")).Attributes.Add("onclick", //"javascript:SelectAll('" +
// ((CheckBox)e.Row.FindControl("chkSelectAll")).ClientID + "')");[/COLOR][/B]
string[] arrIDs = this.Hdteste.Value.Split(new char[] { '|' });
CheckBox cb = (CheckBox)e.Row.FindControl("chk1");
string ID = grvteste.DataKeys[e.Row.RowIndex].Value.ToString();
if (Array.IndexOf(arrIDs, ID) != -1)
{
cb.Checked = true;
}
}
}
private void loaddados()
{
ENB.BussinessLayer.ENBStats oStats = new ENB.BussinessLayer.ENBStats();
DataTable dt = oStats.ENBEntitySELByMatch("", 0);
grvteste.DataSource = dt;
grvteste.DataBind();
dt = null;
}
}
}
isto funciona tdo na perfeição expeto quando descomento a linha a vermelho
do tipo
isto mostra uma grid com dados em que ao checarmos um e mudarmos de pagina de mesma e ,voltarmos a traz ele mantem checkado, a linha que esta a vermelho serve para utilizar o javascript e checar e deschecar tdos ao seleccionar e desceleccionar a check do header, ou seja é esta ultima questão que não funciona
no caso de eu tirar o code que guarda os checks e utilizar apenas o que faz check all ele ja funciona para o check all
ou seja
so funciona ou para um ou para outro
eu gostava que funciona-se com as duas funcionalidades
gstava de um help