<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" EnableViewState="False" width="100%"> <Columns> <dx:GridViewDataTextColumn Caption="Control Field" FieldName="Name" VisibleIndex="0"> <HeaderStyle Font-Bold="True" HorizontalAlign="Left" /> <CellStyle HorizontalAlign="Left"> </CellStyle> </dx:GridViewDataTextColumn> <dx:GridViewDataColumn VisibleIndex="1"> <CellStyle HorizontalAlign="Center"> </CellStyle> <HeaderTemplate> <dx:ASPxCheckBox ID="cbViewAll" runat="server" ToolTip="Select View ALL"> </dx:ASPxCheckBox> </HeaderTemplate> <DataItemTemplate> <dx:ASPxCheckBox ID="cbView" Checked='<%# Eval("status") %>' CheckBoxStyle-HorizontalAlign="Center" runat="server"> </dx:ASPxCheckBox> </DataItemTemplate> </dx:GridViewDataColumn> <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="2"> <HeaderTemplate> <dx:ASPxCheckBox ID="cbInsertAll" runat="server" ToolTip="Select Insert ALL"> </dx:ASPxCheckBox> </HeaderTemplate> </dx:GridViewCommandColumn> <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="3"> <HeaderTemplate> <dx:ASPxCheckBox ID="cbUpdateAll" runat="server" ToolTip="Select Update ALL"> </dx:ASPxCheckBox> </HeaderTemplate> </dx:GridViewCommandColumn> <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="4"> <HeaderTemplate> <dx:ASPxCheckBox ID="cbDeleteAll" runat="server" ToolTip="Select Delete ALL"> </dx:ASPxCheckBox> </HeaderTemplate> </dx:GridViewCommandColumn> </Columns> <SettingsDataSecurity AllowDelete="False" AllowInsert="False" /> <Styles> <Header HorizontalAlign="Center" /> </Styles> <SettingsBehavior AllowDragDrop="false" /> <Settings ShowGroupPanel="false"></Settings> <SettingsPager PageSize="10" /> <SettingsText EmptyDataRow="Doesn't have a data" /> </dx:ASPxGridView>
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using MesinAbsensiLib.DataAccess.Extended; using MesinAbsensiLib; using System.Text.RegularExpressions; using System.Data.Entity; public partial class AccessControl : System.Web.UI.Page { MesinAbsensiEntities md = new MesinAbsensiEntities(); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { providerights(); GetAccessControl(); } Alert.Visible = false; } private void providerights() { HttpCookie uCookies = Request.Cookies["uCookies"]; string UserName = uCookies["UserID"]; //int AreaId = Convert.ToInt32(uCookies["AreaID"]); int ControlId = Convert.ToInt32(uCookies["AccessControlID"]); // string Roll = uCookies["Roll"]; var result1 = md.sp_getViewStatus(ControlId, 2).ToList(); if (result1[0].Value == false) { //Response.Redirect("../Error.aspx?ms=AccessD"); Response.Redirect("../error.aspx?ms=AccessD"); } } private void GetAccessControl() { var result = md.tblAccessControls.ToList(); if (result.Count > 0) { ddlAccessControl.Items.Clear(); ddlAccessControl.DataSource = result; ddlAccessControl.DataTextField = "Name"; ddlAccessControl.DataValueField = "Id"; ddlAccessControl.DataBind(); ddlAccessControl.Items.Insert(0, "--Select--"); } else { ddlAccessControl.Items.Clear(); ddlAccessControl.Items.Insert(0, "--Select--"); } } protected void btnSave_Click(object sender, EventArgs e) { int ControlId=Convert.ToInt32(ddlAccessControl.SelectedValue); foreach (GridViewRow item in gv.Rows) { Int32 Id = Convert.ToInt32(((Label)item.FindControl("id")).Text); Int32 FId = Convert.ToInt32(((Label)item.FindControl("fid")).Text); bool Status = ((CheckBox)item.FindControl("chkStatus")).Checked; // bool ViewStatus = ((CheckBox)item.FindControl("chkviewStatus")).Checked; if (FId == 0) { tblControlFieldAllocate tbl = new tblControlFieldAllocate(); tbl.ControlId = ControlId; tbl.ControlField = Id; tbl.Status = Status; // tbl.ViewStatus = ViewStatus; md.tblControlFieldAllocates.Add(tbl); md.SaveChanges(); } else { var result = md.tblControlFieldAllocates.Where(c => c.Id == FId).ToList(); if (result.Count > 0) { result[0].ControlId = ControlId; result[0].ControlField = Id; result[0].Status = Status; // result[0].ViewStatus = ViewStatus; md.SaveChanges(); } } } Alert.Visible = true; GETDATA(); } private void GETDATA() { if(ddlAccessControl.SelectedIndex!=0) { int ControlId=Convert.ToInt32(ddlAccessControl.SelectedValue); var result = (from AC in md.tblControlFields join AFA in md.tblControlFieldAllocates on AC.Id equals AFA.ControlField into gj from PAR in gj.Where(c => c.ControlId == ControlId).DefaultIfEmpty() orderby AC.Orders ascending select new { AC.Id, FId = (PAR.Id == null) ? 0 : PAR.Id, AC.Name, status = (PAR.Status == null) ? false : PAR.Status // ViewStatus = (PAR.ViewStatus == null) ? false : PAR.ViewStatus }).ToList(); gv.DataSource = result; gv.DataBind(); } } protected void ddlAccessControl_SelectedIndexChanged(object sender, EventArgs e) { GETDATA(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)