private int DeleteOldData()
 {
     string RoleId = ddlRoleList.SelectedValue;
     int PermissionId = Convert.ToInt32(ddlPermissionList.SelectedValue);
     TabPermissionController tab_permission_obj = new TabPermissionController();
     DataTable dt = tab_permission_obj.GetListByRoleIdPermissionId(RoleId, PermissionId);
     int TabPermissionId = -1, result = -1;
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         TabPermissionId = Convert.ToInt32(dt.Rows[i]["TabPermissionId"].ToString());
         result = tab_permission_obj.DeleteTabPermission(TabPermissionId);
     }
     return result;
 }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string TabId = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();   
                string RoleId = ddlRoleList.SelectedValue;                             
                int PermissionId = Convert.ToInt32(ddlPermissionList.SelectedValue);
                string SelectedTabId = null, UserId=null;                
                TabPermissionController tab_permission_obj = new TabPermissionController();
                DataTable dt = tab_permission_obj.GetListByRoleIdPermissionId(RoleId, PermissionId);                           

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    SelectedTabId = dt.Rows[i]["TabId"].ToString();
                    if(dt.Rows[i]["UserId"].ToString() != string.Empty)
                        UserId = dt.Rows[i]["UserId"].ToString();     
                    else
                    {
                        if (Session["UserId"] != null && Session["UserId"].ToString() != string.Empty)
                            UserId = Session["UserId"].ToString();
                    }

                    if (TabId == SelectedTabId)
                    {
                        CheckBox chkSelectedPermissionRight = (CheckBox)e.Row.Cells[2].FindControl("chkSelectedPermissionRight");
                        if (chkSelectedPermissionRight != null)
                            chkSelectedPermissionRight.Checked = true;

                        CheckBox chkSelectedAllowAccessRight = (CheckBox)e.Row.Cells[3].FindControl("chkSelectedAllowAccessRight");
                        if (chkSelectedAllowAccessRight != null)
                            chkSelectedAllowAccessRight.Checked = true;

                        //TextBox txtUserId = (TextBox)e.Row.Cells[4].FindControl("txtUserId");
                        //txtUserId.Text = UserId;
                        //txtUserId.Attributes.Add("value", txtUserId.Text);

                        DropDownList ddlUserList = (DropDownList)e.Row.FindControl("ddlUserList");
                        PopulateUserList(ddlUserList, UserId);
                    }
                }               
            }                   
        }