i am new in this forum, but i have to ask u guys some question, because this problem is not found even closest method, so i want to make this group of checkbox like this : The Default Form so i have to make it like this one : Wrong Form :: but above form is not fully functioning, when i checked the header of the gridview, all the itemTemplate must be checked also, and of course, Green Checkbox, and the problem is : WHEN I PUT THE FLAT(USE TO MAKE CHECKBOX GREEN), THE LEAGUE CLASS IS NOT FUNCTIONING
So here is the code, i put css of green checkbox called flat and specific function when u check the header, all itemTemplate Checkbox get Checked called league
here is the aspx code:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/PopUp.Master" AutoEventWireup="true" CodeBehind="SelectLeague.aspx.cs" Inherits="HMB.Sbop.WebGL.Pages.Trading.SelectLeague" %>
<%@ OutputCache Duration="1" Location="None" VaryByParam="None"%>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
$(document).ready(function () {
$('.flat').iCheck({
checkboxClass: 'icheckbox_flat-green'
});
$('body').css('background', 'transparent');
// checked header, addClass per row
$('th[class^="league"] :checkbox').each(function () {
var clsName = $(this).closest('th[class^="league"]').prop('class');
$('span.' + clsName + ' :checkbox:checked').closest('tr').addClass('selected2');
if ($('span.' + clsName + ' :checkbox').length == $('span.' + clsName + ' :checkbox:checked').length) {
this.checked = true;
}
});
//event checked all per sport
$('th[class^="league"] :checkbox').on('click', function () {
checkAll(this.id, $(this).closest('th[class^="league"]').prop('class'));
});
//event row table.tr
$('tr:not(.separator)').addClass('trChecked')
.on('mousedown', function (e) {
if (e.target.tagName.toUpperCase() != 'INPUT') {
var $chb = $(this).find('input:checkbox');
var isChecked = $chb.is(':checked');
$chb.prop('checked', !isChecked);
if (!isChecked == true) {
$(this).addClass('selected2');
}
else {
$(this).removeClass('selected2');
}
checkHeaderAll(this, 'tr');
}
});
});
//FUNGSI DI BAWAH UNTUK HEADER AGAR HIGHLIGHT SELECTED COLUMNS
function checkAll(id, className) {
$('span.' + className + ' :checkbox')
.prop('checked', $('#' + id).prop('checked'))
.each(function (event) {
if (this.checked) {
$(this).closest('tr').addClass('selected2');
}
else {
$(this).closest('tr').removeClass('selected2');
}
});
}
function check(id) {
$(document).on('click', '#' + id, function (e) {
if ($(this).is(':checked') == true) {
$(this).closest('tr').addClass('selected2');
} else {
$(this).closest('tr').removeClass('selected2');
}
checkHeaderAll(this, 'chb');
});
}
function checkHeaderAll(obj, mode) {
var $spnCls = '';
if (mode == 'chb') {
$spnCls = $(obj).closest('span').prop('class');
}
else if (mode == 'tr') {
$spnCls = $(obj).find('span').prop('class');
}
var $no = $spnCls.replace('league', '');
if ($('span.' + $spnCls).length == $('span.' + $spnCls + ' :checkbox:checked').length) {
$$('chkAllLeague' + $no).prop('checked', true);
} else {
$$('chkAllLeague' + $no).prop('checked', false);
}
}
function $$(id, context) {
var el = $("#" + id, context);
if (el.length < 1)
el = $("[id$=_" + id + "]", context);
return el;
}
function pageLoad(sender, args) {
if (args.get_isPartialLoad()) {
$('.flat').iCheck({
checkboxClass: 'icheckbox_flat-green'
});
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="dvLeague" style="position:absolute;height:480px;width:510px;top:25px;overflow:auto;">
<asp:GridView ID="gvLeague" runat="server" Width="490px" AutoGenerateColumns="false"
CssClass="table table-bordered responsive-utilities"
HeaderStyle-CssClass="separator"
OnRowDataBound="gvLeague_RowDataBound">
<Columns>
<asp:TemplateField HeaderStyle-Width="40px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:CheckBox ID="chkAllLeague" runat="server"/>
</HeaderTemplate>
<HeaderStyle CssClass="league flat"/>
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkLeague"/>
<asp:Literal runat="server" ID="ltrLeagueID" Visible="false" Text='<%# Eval("League_ID") %>'></asp:Literal>
<asp:Literal runat="server" ID="ltrLeagueSelected" Visible="false" Text='<%# Eval("Is_Selected") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Literal runat="server" ID="ltrLeagueSportName" Text='<%# Eval("Sport_Name") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Literal runat="server" ID="ltlLeagueEventsName" Text='<%# Eval("League_Name") %>'></asp:Literal>
<asp:Literal ID="ltrNewHeader" runat="server"></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:UpdatePanel ID="upPopUp" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%--<div style="position:absolute; top: 1px;right:25px;">
<asp:Button ID="btnSubmitLeagueHdr" runat="server" Text="Submit" CssClass="btn btn-primary" OnClick="btnSubmitLeague_Click" />
</div> --%>
<div style="position:absolute;bottom:1px;right:25px;">
<asp:Button ID="btnSubmitLeague" runat="server" Text="Submit" CssClass="btn btn-primary" OnClick="btnSubmitLeague_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
and this is the behind code :
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HMB.Sbop.Common;
using HMB.Sbop.Common.Extensions;
using HMB.Sbop.Entities;
namespace HMB.Sbop.WebGL.Pages.Trading
{
public partial class SelectLeague : System.Web.UI.Page
{
#region Field
Entities.Trading.SelectLeague selectLeague = new Entities.Trading.SelectLeague();
#endregion
#region Properties
private string fromdate
{
get
{
object o = ViewState["fromdate"];
return (o == null) ? String.Empty : (string)o;
}
set
{
ViewState["fromdate"] = value;
}
}
private string todate
{
get
{
object o = ViewState["todate"];
return (o == null) ? String.Empty : (string)o;
}
set
{
ViewState["todate"] = value;
}
}
private string groupname
{
get
{
object o = ViewState["groupname"];
return (o == null) ? String.Empty : (string)o;
}
set
{
ViewState["groupname"] = value;
}
}
private string os
{
get
{
object o = ViewState["os"];
return (o == null) ? String.Empty : (string)o;
}
set
{
ViewState["os"] = value;
}
}
private string page
{
get
{
object o = ViewState["page"];
return (o == null) ? String.Empty : (string)o;
}
set
{
ViewState["page"] = value;
}
}
private string popupID
{
get
{
object o = ViewState["popupID"];
return (o == null) ? String.Empty : (string)o;
}
set
{
ViewState["popupID"] = value;
}
}
private string TempSportID
{
get { return ViewState["TempSportID"].ToString(); }
set { ViewState["TempSportID"] = value; }
}
private string CssClass
{
get { return ViewState["CssClass"].ToString(); }
set { ViewState["CssClass"] = value; }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fromdate = Request.QueryString["fromdate"];
todate = Request.QueryString["todate"];
groupname = Request.QueryString["groupname"];
page = Request.QueryString["page"];
popupID = Request.QueryString["popupID"];
os = (string.IsNullOrEmpty(Request.QueryString["OS"]) == true) ? "N" : Request.QueryString["OS"];
bindLeague();
}
}
protected void bindLeague()
{
int columnCount = 3;
CssClass = "";
TempSportID = "";
DataTable dtLeague = new DataTable();
selectLeague.GroupName = groupname;
selectLeague.FromEarlyDate = fromdate;
selectLeague.ToEarlyDate = todate;
selectLeague.PopupID = popupID;
selectLeague.OS = os;
if (groupname == "Forecast-Post")
{
dtLeague = selectLeague.ListGridSelectLeaguePost(selectLeague);
}
else
{
dtLeague = selectLeague.ListGridSelectLeague(selectLeague);
}
if (string.IsNullOrEmpty(selectLeague.LastErrorMessage))
{
if (dtLeague != null && dtLeague.Rows.Count == 0)
{
dtLeague.Rows.Add(dtLeague.NewRow());
columnCount = 0;
}
gvLeague.DataSource = dtLeague;
gvLeague.DataBind();
if (columnCount == 0)
{
columnCount = gvLeague.Rows[0].Cells.Count;
gvLeague.Rows[0].Cells.Clear();
gvLeague.Rows[0].Cells.Add(new TableCell());
gvLeague.Rows[0].Cells[0].ColumnSpan = columnCount;
gvLeague.Rows[0].Cells[0].Text = Lang.GetString("No Records");
gvLeague.Rows[0].HorizontalAlign = HorizontalAlign.Center;
}
}
}
protected void gvLeague_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[1].Text = Lang.GetString("Sport");
e.Row.Cells[2].Text = Lang.GetString("League Name");
}
if (e.Row.RowType == DataControlRowType.DataRow && gvLeague.Rows.Count >= 0 && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
{
CheckBox chkLeague = e.Row.FindControl("chkLeague") as CheckBox;
Literal ltrLeagueID = (Literal)e.Row.FindControl("ltrLeagueID");
string sportID = ltrLeagueID.Text.Trim().Left(2);
if (e.Row.RowIndex == 0)
{
TempSportID = sportID;
}
else
{
if (!TempSportID.Equals(sportID))
{
Literal ltrNewHeader = (Literal)gvLeague.Rows[e.Row.RowIndex - 1].FindControl("ltrNewHeader");
ltrNewHeader.Text = "</tr><tr class=\"separator\" style=\"text-align:center;\"> <th class=\"league" + sportID + "\" style=\"text-align:center;\"><input id=\"chkAllLeague" + sportID + "\" class=\"text-center\" type=\"checkbox\" /></th><th>" + Lang.GetString("Sport") + "</th><th>" + Lang.GetString("League Name") + "</th> </tr>";
TempSportID = sportID;
CssClass = sportID;
}
}
chkLeague.Attributes.Add("OnClick", "javascript:check('" + chkLeague.ClientID + "')");
chkLeague.CssClass = "league" + CssClass;
Literal ltrLeagueSelected = e.Row.FindControl("ltrLeagueSelected") as Literal;
if (ltrLeagueSelected.Text == "Y")
{
chkLeague.Checked = true;
}
else
{
chkLeague.Checked = false;
}
}
}
protected void btnSubmitLeague_Click(object sender, EventArgs e)
{
CheckBox chkLeague;
Literal ltrLeagueID;
string tmpLeagueID = "";
foreach (GridViewRow row in gvLeague.Rows)
{
chkLeague = (CheckBox)row.FindControl("chkLeague");
ltrLeagueID = (Literal)row.FindControl("ltrLeagueID");
if (chkLeague.Checked)
{
tmpLeagueID += ltrLeagueID.Text + ",";
}
}
selectLeague.GroupName = groupname;
selectLeague.LeagueIDs = (tmpLeagueID != "") ? tmpLeagueID.Substring(0, tmpLeagueID.Length - 1) : "";
selectLeague.FromEarlyDate = fromdate;
selectLeague.ToEarlyDate = todate;
selectLeague.PopupID = popupID;
if (groupname == "Forecast-Post")
{
selectLeague.ProcUpdSelectLeaguePost(selectLeague);
}
else
{
selectLeague.ProcUpdSelectLeague(selectLeague);
}
//if (!string.IsNullOrEmpty(selectLeague.LastErrorMessage)){}
string strFunction = string.Empty;
if (page == "InstantBet")
{
strFunction = "window.parent.Initialization();window.parent.closeDialog('dvSelectLeague');";
}
else if (page == "MOLS") // Darius 2013-11-08 Tambah pengecekan untuk MO Lightstreamer
{
strFunction += "window.close();";
}
else
{
strFunction = "if(window.opener && !window.opener.closed){window.opener.LoadData();}";
strFunction += "window.close();";
//strFunction = "window.parent.LoadData();window.parent.closeDialog('dvSelectLeague');";
}
ScriptManager.RegisterClientScriptBlock(this, typeof(UpdatePanel), UniqueID, strFunction, true);
upPopUp.Update();
}
}
}
Thank You
Aucun commentaire:
Enregistrer un commentaire