Scenario: I have a gridview that loads morethan 300 rows..but it takes a minute to save the value of checkboxes..how can i resolved this..
ASPX
<asp:GridView ID="gridRolApp" runat="server" ClientIDMode="Static"
BorderColor="#0070C0" GridLines="None" AutoGenerateColumns="False"
Width="1100px" UseAccessibleHeader="false" CssClass="Content"
datakeynames="User_Pidx,BusinessUnit,Department">
<Columns>
<asp:TemplateField >
<HeaderStyle Width="200px"/>
<HeaderTemplate>BUSINESS UNIT</HeaderTemplate>
<ItemStyle BackColor="#EFEFEF" Width="200px" Font-Size="12px"/>
<ItemTemplate>
<%#Eval("Plant_Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>DEPARTMENT</HeaderTemplate>
<%#Eval("Dept_Name")%>
<HeaderStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:CheckBox runat="server" id="chkAllDeptHead" AutoPostBack="True" oncheckedchanged="chkAllDeptHead_CheckedChanged" />
<br>DH
</HeaderTemplate>
<center><asp:CheckBox runat="server" id="chkDeptHead" OnDataBinding="chkDeptHead_DataBinding"/></center>
<asp:CheckBox runat="server" id="chkAllSM" AutoPostBack="True" oncheckedchanged="chkAllSM_CheckedChanged" />
<br>SM
<center><asp:CheckBox runat="server" id="chkSM" OnDataBinding="chkSM_DataBinding"/></center>
<asp:CheckBox runat="server" id="chkAllTMM" AutoPostBack="True" oncheckedchanged="chkAllTMM_CheckedChanged" />
<br>TMM
<center><asp:CheckBox runat="server" id="chkTMM" OnDataBinding="chkTMM_DataBinding" /></center>
<asp:CheckBox runat="server" id="chkAllHRM" AutoPostBack="True" oncheckedchanged="chkAllHRM_CheckedChanged" />
<br />HRM
<center><asp:CheckBox runat="server" id="chkHRM" OnDataBinding="chkHRM_DataBinding"/></center>
<asp:CheckBox runat="server" id="chkAllFM" AutoPostBack="True" oncheckedchanged="chkAllFM_CheckedChanged" />
<br />FM
<center><asp:CheckBox runat="server" id="chkFM" OnDataBinding="chkFM_DataBinding"/></center>
<asp:CheckBox runat="server" id="chkAllFD" AutoPostBack="True" oncheckedchanged="chkAllFD_CheckedChanged" />
<br />FD
<center><asp:CheckBox runat="server" id="chkFD" OnDataBinding="chkFD_DataBinding" /></center>
<asp:CheckBox runat="server" id="chkAllGM" AutoPostBack="True" oncheckedchanged="chkAllGM_CheckedChanged" />
<br />GM
<center><asp:CheckBox runat="server" id="chkGM" OnDataBinding="chkGM_DataBinding" /></center>
<asp:CheckBox runat="server" id="chkAllSGM" AutoPostBack="True" oncheckedchanged="chkAllSGM_CheckedChanged" />
<br />SGM
<center><asp:CheckBox runat="server" id="chkSGM" OnDataBinding="chkSGM_DataBinding"/></center>
<asp:CheckBox runat="server" id="chkAllFC" AutoPostBack="True" oncheckedchanged="chkAllFC_CheckedChanged" />
<br />FC
<center><asp:CheckBox runat="server" id="chkFC" OnDataBinding="chkFC_DataBinding" /></center>
<asp:CheckBox runat="server" id="chkAllVPFHead" AutoPostBack="True" oncheckedchanged="chkAllVPFHead_CheckedChanged" />
<br />VP-FH
<center><asp:CheckBox runat="server" id="chkVPFHead" OnDataBinding="chkVPFHead_DataBinding" /></center>
<asp:CheckBox runat="server" id="chkAllVPML" AutoPostBack="True" oncheckedchanged="chkAllVPML_CheckedChanged" />
<br />VP-M&L
<center><asp:CheckBox runat="server" id="chkVPML" OnDataBinding="chkVPML_DataBinding" /></center>
<asp:CheckBox runat="server" id="chkAllCorpLegal" AutoPostBack="True" oncheckedchanged="chkAllCorpLegal_CheckedChanged" />
<br />CLS
<center><asp:CheckBox runat="server" id="chkCorpLegal" OnDataBinding="chkCorpLegal_DataBinding"/></center>
<asp:CheckBox runat="server" id="chkAllVPHR" AutoPostBack="True" oncheckedchanged="chkAllVPHR_CheckedChanged" />
<br />VP-HR
<center><asp:CheckBox runat="server" id="chkVPHR" OnDataBinding="chkVPHR_DataBinding" /></center>
<asp:CheckBox runat="server" id="chkAllEVPSales" AutoPostBack="True" oncheckedchanged="chkAllEVPSales_CheckedChanged" />
<br />EVPSales
<center><asp:CheckBox runat="server" id="chkEVPSales" OnDataBinding="chkEVPSales_DataBinding" /></center>
<asp:CheckBox runat="server" id="chkAllCFO" AutoPostBack="True" oncheckedchanged="chkAllCFO_CheckedChanged" />
<br />CFO
<center><asp:CheckBox runat="server" id="chkCFO" OnDataBinding="chkCFO_DataBinding" /></center>
<asp:CheckBox runat="server" id="chkAllPres" AutoPostBack="True" />
<br />Pres
<center><asp:CheckBox runat="server" id="chkPres" OnDataBinding="chkPres_DataBinding"/></center>
<asp:CheckBox runat="server" id="chkAllCEO" AutoPostBack="True" oncheckedchanged="chkAllCEO_CheckedChanged" />
<br />CEO
<center><asp:CheckBox runat="server" id="chkCEO" OnDataBinding="chkCEO_DataBinding"/></center>
</Columns>
<HeaderStyle CssClass="GridviewScrollHeader" />
<RowStyle CssClass="GridviewScrollItem" />
<PagerStyle CssClass="GridviewScrollPager" />
</asp:GridView>
<asp:Button runat="server" Text="Save" ID="btnSave" Width="100" CssClass="TextDrop" onclick="btnSave_Click" />
protected void btnSave_Click(object sender, EventArgs e)
{
if (txtValidation().Equals(true))
CLMSDataContext context = new CLMSDataContext();
try
context.ExecuteCommand("UPDATE Dim_User SET PosLoc_Abbreviation = '" + txtPosLocAbb.Text + "', " + Environment.NewLine +
" Active ='"+ chkActive.Checked +"'," + Environment.NewLine +
" Admin ='" + chkAdmin.Checked + "'," + Environment.NewLine +
" RealTime_Notification ='" + ChkRTNotification.Checked + "'," + Environment.NewLine +
" LastName = '" + txtLastName.Text + "', " + Environment.NewLine +
" FirstName = '" + txtFirstName.Text + "', " + Environment.NewLine +
" MiddleInitial = '" + txtMI.Text.Trim() + "', " + Environment.NewLine +
" NickName = '" + txtAKA.Text + "', " + Environment.NewLine +
" SMTPAddress = '" + txtEmail.Text + "', " + Environment.NewLine +
" Plant_PIdx = '" + defaultBU.SelectedValue + "', Dept_PIdx = '" + defaultDept.SelectedValue + "' " + Environment.NewLine +
" WHERE User_Idx = '" + Convert.ToInt64(Session["UserID"]) + "'");
bool chkboxIsChecked = false;
List<Dim_User_Role> deleteRole = (from key in context.Dim_User_Roles
where key.User_PIdx == Convert.ToInt64(Session["UserID"])
select key).ToList();
context.Dim_User_Roles.DeleteAllOnSubmit(deleteRole);
context.SubmitChanges();
foreach (GridViewRow row in gridRolApp.Rows)
string pUserID = gridRolApp.DataKeys[row.RowIndex].Values["User_Pidx"].ToString();
string pPlantID = gridRolApp.DataKeys[row.RowIndex].Values["BusinessUnit"].ToString();
string pDeptID = gridRolApp.DataKeys[row.RowIndex].Values["Department"].ToString();
chkboxIsChecked = false;
CheckBox chkDeptHead = (CheckBox)row.FindControl("chkDeptHead");
if ((chkDeptHead != null) && (chkDeptHead.Checked == true))
chkboxIsChecked = true;
}
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkDeptHead"), chkboxIsChecked);
CheckBox chkSM = (CheckBox)row.FindControl("chkSM");
if ((chkSM != null) && (chkSM.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkSM"), chkboxIsChecked);
CheckBox chkTMM = (CheckBox)row.FindControl("chkTMM");
if ((chkTMM != null) && (chkTMM.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkTMM"), chkboxIsChecked);
CheckBox chkHRM = (CheckBox)row.FindControl("chkHRM");
if ((chkHRM != null) && (chkHRM.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkHRM"), chkboxIsChecked);
CheckBox chkFM = (CheckBox)row.FindControl("chkFM");
if ((chkFM != null) && (chkFM.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkFM"), chkboxIsChecked);
CheckBox chkFD = (CheckBox)row.FindControl("chkFD");
if ((chkFD != null) && (chkFD.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkFD"), chkboxIsChecked);
CheckBox chkGM = (CheckBox)row.FindControl("chkGM");
if ((chkGM != null) && (chkGM.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkGM"), chkboxIsChecked);
CheckBox chkSGM = (CheckBox)row.FindControl("chkSGM");
if ((chkSGM != null) && (chkSGM.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkSGM"), chkboxIsChecked);
CheckBox chkFC = (CheckBox)row.FindControl("chkFC");
if ((chkFC != null) && (chkFC.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkFC"), chkboxIsChecked);
CheckBox chkVPFHead = (CheckBox)row.FindControl("chkVPFHead");
if ((chkVPFHead != null) && (chkVPFHead.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkVPFHead"), chkboxIsChecked);
CheckBox chkVPML = (CheckBox)row.FindControl("chkVPML");
if ((chkVPML != null) && (chkVPML.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkVPML"), chkboxIsChecked);
CheckBox chkCorpLegal = (CheckBox)row.FindControl("chkCorpLegal");
if ((chkCorpLegal != null) && (chkCorpLegal.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkCorpLegal"), chkboxIsChecked);
CheckBox chkVPHR = (CheckBox)row.FindControl("chkVPHR");
if ((chkVPHR != null) && (chkVPHR.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkVPHR"), chkboxIsChecked);
CheckBox chkEVPSales = (CheckBox)row.FindControl("chkEVPSales");
if ((chkEVPSales != null) && (chkEVPSales.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkEVPSales"), chkboxIsChecked);
CheckBox chkCFO = (CheckBox)row.FindControl("chkCFO");
if ((chkCFO != null) && (chkCFO.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkCFO"), chkboxIsChecked);
CheckBox chkPres = (CheckBox)row.FindControl("chkPres");
if ((chkPres != null) && (chkPres.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkPres"), chkboxIsChecked);
CheckBox chkCEO = (CheckBox)row.FindControl("chkCEO");
if ((chkCEO != null) && (chkCEO.Checked == true))
RoleSaving(Convert.ToInt64(pUserID), Convert.ToInt64(pPlantID), Convert.ToInt64(pDeptID), getRole("chkCEO"), chkboxIsChecked);
successTitle.InnerText = "User Registration";
pSuccessMessage1.InnerText = "User successfully registered!";
btnSuccessOk.Focus();
modpopSuccess.Show();
catch (Exception ex)
pSuccessMessage1.InnerText = ex.Message;
finally
{ context.Dispose(); }
else
pSuccessMessage1.InnerText = "Incomplete field!";
private Int64 getRole(string RoleStr)
Int64 roleid = 0;
switch (RoleStr)
//case "chkInitiator": roleid = 1; break;
case "chkDeptHead": roleid = 2; break;
case "chkSM": roleid = 3; break;
case "chkTMM": roleid = 4; break;
case "chkHRM": roleid = 5; break;
case "chkFM": roleid = 6; break;
case "chkFD": roleid = 7; break;
case "chkGM": roleid = 8; break;
case "chkSGM": roleid = 9; break;
case "chkFC": roleid = 10; break;
case "chkVPFHead": roleid = 11; break;
case "chkVPML": roleid = 12; break;
case "chkCorpLegal": roleid = 13; break;
case "chkVPHR": roleid = 14; break;
case "chkEVPSales": roleid = 15; break;
case "chkCFO": roleid = 16; break;
case "chkPres": roleid = 17; break;
case "chkCEO": roleid = 18; break;
default: roleid = 0; break;
return roleid;
private void RoleSaving(Int64 userid, Int64 plant, Int64 dept, Int64 role, bool isChecked)
var roleRec = (from r in context.Dim_User_Roles
where r.User_PIdx == userid &&
r.Dept_PIdx == dept &&
r.Plant_PIdx == plant &&
r.Role_PIdx == role
select r).ToList();
if (roleRec.Count == 0)
if (isChecked == true)
Dim_User_Role uRol = new Dim_User_Role();
uRol.User_PIdx = userid;
uRol.Plant_PIdx = plant;
uRol.Dept_PIdx = dept;
uRol.Role_PIdx = role;
context.Dim_User_Roles.InsertOnSubmit(uRol);
catch (Exception e)
context.Transaction.Rollback();
Response.Write(e.Message);
{ Response.Write(e.Message); return; }
context.Dispose();