private void BindColumns(DataTable dt, string tableName, string primaryKeyId, bool hideData, bool isTesting, string[] validColumns, string userPreferenceCategory) { gridFormatdt = GetGridFormatSettings(); // boolean values set for the fields and procedures in the GridView var procedureHide = hideData; var fieldHide = false; // Create a string array for DataNavigationUrlFields var str = new string[2]; str[0] = primaryKeyId; str[1] = dt.Columns[0].ColumnName; // Create rest of columns based on what user has access to ... var key = "Default"; var disableLink = hideData; var idColumn = new DataColumn(str[0]); if (idColumn != null) { for (var i = 0; i < validColumns.Length; i++) { if (validColumns[i].Equals(idColumn.ColumnName)) { if (!string.IsNullOrEmpty(GroupByField) || idColumn.ColumnName != GroupByField) { // dynamically add hyperlink fields from the data table SetHyperLink(idColumn, str, tableName, disableLink); } } } } foreach (DataRow row in gridFormatdt.Rows) { //Considering all the columns have their width fixed from the Database totalGridColumnWidth += Double.Parse(row[FieldConfiguration.DataColumns.Width].ToString()); } foreach (var t in validColumns) { // get the column from the data table if (!t.Equals(idColumn.ColumnName)) { var dataColumn = dt.Columns[t]; //var i = 0; //str[0] = t; //str[1] = t; if (dataColumn != null) { if (string.IsNullOrEmpty(GroupByField) || dataColumn.ColumnName != GroupByField) { //if (dataColumn.ColumnName.ToLower() != idColumn.ColumnName.ToLower()) // dynamically add hyperlink fields from the data table SetHyperLink(dataColumn, str, tableName, disableLink); } } } } if (SessionVariables.ApplicationUserRoles == null) { ApplicationCommon.SetApplicationUserRoles(); } var roles = SessionVariables.ApplicationUserRoles; var role = roles.Find(item => item.ApplicationRole == "System Coordinator"); if (role != null) { disabledelete = false; } else { disabledelete = true; } // based on another bool parameters indicating if action buttons should show // add action button / links if (IsUpdateColumn) { var userDetailVisibility = ApplicationCommon.GetUserPreferenceByKeyAsBoolean(ApplicationCommon.GridDetailLinkVisibleKey, userPreferenceCategory); if (userDetailVisibility) { var userAction = ApplicationCommon.GetUserPreferenceByKey(ApplicationCommon.GridDefaultClickActionKey); //var userAction = ApplicationCommon.GetDefaultActionLink(); if (userAction == "update") { ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_DETAIL, tableName, procedureHide); } else { ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_UPDATE, tableName, procedureHide); } } } if (IsDeleteColumn) { var userDeleteVisibility = ApplicationCommon.GetUserPreferenceByKeyAsBoolean(ApplicationCommon.GridDeleteLinkVisibleKey, userPreferenceCategory); if (userDeleteVisibility) { ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_DELETE, tableName, procedureHide); } } }
private void BindColumns(DataTable dt, string tableName, string primaryKeyId, bool hideData, bool isTesting) { gridFormatdt = GetGridFormatSettings(); // if (IsPostBack) return; // Create Column 0 --> PrimaryKey // Declare the bound field and allocate memory for the bound field. // Initalize the DataField value. //var bfield = new BoundField { DataField = primaryKeyId }; //bfield.ItemStyle.HorizontalAlign = HorizontalAlign.Center; //bfield.HeaderText = dt.Columns[0].ColumnName.Replace("Id", " Id"); //bfield.Visible = isTesting; //// ConvertStringArrayToString(dt.Columns[0].ColumnName.Split(new char[] { 'I' }, 1)); //// Add the newly created bound field to the GridView. //if(!dt.Columns[0].ColumnName.Equals("PersonId")) //MainGridView.Columns.Add(bfield); // boolean values set for the fields and procedures in the GridView var procedureHide = hideData; var fieldHide = false; // Create a string array for DataNavigationUrlFields var str = new string[2]; str[0] = primaryKeyId; str[1] = dt.Columns[0].ColumnName; // Create rest of columns based on what user has access to ... var key = "Default"; var disableLink = hideData; var validColumns = _getColumnDelegate(); //if (!string.IsNullOrEmpty(GroupByField) && validColumns.Contains(GroupByField)) //{ // //validColumns.d //} var idColumn = new DataColumn(str[0]); if (idColumn != null) { for (var i = 0; i < validColumns.Length; i++) { if (validColumns[i].Equals(idColumn.ColumnName)) { if (!string.IsNullOrEmpty(GroupByField) || idColumn.ColumnName != GroupByField) { // dynamically add hyperlink fields from the data table SetHyperLink(idColumn, str, tableName, disableLink); } } } } foreach (DataRow row in gridFormatdt.Rows) { //Considering all the columns have their width fixed from the Database totalGridColumnWidth += Double.Parse(row[FieldConfiguration.DataColumns.Width].ToString()); } foreach (var t in validColumns) { // get the column from the data table if (!t.Equals(idColumn.ColumnName)) { var dataColumn = dt.Columns[t]; //var i = 0; //str[0] = t; //str[1] = t; if (dataColumn != null) { if (string.IsNullOrEmpty(GroupByField) || dataColumn.ColumnName != GroupByField) { //if (dataColumn.ColumnName.ToLower() != idColumn.ColumnName.ToLower()) // dynamically add hyperlink fields from the data table SetHyperLink(dataColumn, str, tableName, disableLink); } } } } if (SessionVariables.ApplicationUserRoles == null) { ApplicationCommon.SetApplicationUserRoles(); } var roles = SessionVariables.ApplicationUserRoles; var role = roles.Find(item => item.ApplicationRole == "System Coordinator"); if (role != null) { disabledelete = false; } else { disabledelete = true; } // based on another bool parameters indicating if action buttons should show // add action button / links if (IsUpdateColumn) { var userDetailVisibility = ApplicationCommon.GetUserPreferenceByKeyAsBoolean(ApplicationCommon.GridDetailLinkVisibleKey, this.UserPreferenceCategory); if (userDetailVisibility) { var userAction = ApplicationCommon.GetUserPreferenceByKey(ApplicationCommon.GridDefaultClickActionKey); //var userAction = ApplicationCommon.GetDefaultActionLink(); if (userAction == "update") { ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_DETAIL, tableName, procedureHide); } else { ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_UPDATE, tableName, procedureHide); } } } if (IsDeleteColumn) { var userDeleteVisibility = ApplicationCommon.GetUserPreferenceByKeyAsBoolean(ApplicationCommon.GridDeleteLinkVisibleKey, this.UserPreferenceCategory); if (userDeleteVisibility) { ListHelper.AddProcedures(MainGridView, ViewState, str, VIEW_STATE_KEY_DELETE, tableName, procedureHide); } } }