I have a grid that uses paging, frozen headers and autogenerated columns. My issue is when I click on the pager to get to the second row set all the checkboxes are disabled. These work fine on the first page view but then after I click on the any page they are all disabled. There is a <span disabled=disabled">checkbox</span> placed around them. Can't seem to figure out what is causing this.
Thanks
Thanks
<telerik:RadGrid ID="RadGrid1" AllowMultiRowEdit="true" EnableViewState="False" |
AllowAutomaticUpdates="false" MasterTableView-EditMode="InPlace" runat="server" |
AutoGenerateColumns="true" OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound" |
onneeddatasource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender" AllowPaging="True" PageSize="50" PagerStyle-Mode="NextPrevNumericAndAdvanced"> |
<MasterTableView EditMode="InPlace" ClientDataKeyNames="Product" TableLayout="Auto"> |
</MasterTableView> |
<AlternatingItemStyle BackColor="AliceBlue" /> |
<ClientSettings AllowKeyboardNavigation="false" EnableAlternatingItems="false" EnableRowHoverStyle="false"> |
<Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" FrozenColumnsCount="2" /> |
<Selecting AllowRowSelect="false" /> |
</ClientSettings> |
</telerik:RadGrid> |
private DataTable _dt = null; |
protected void Page_Load(object sender, EventArgs e) |
{ |
//Load the data |
ddlContacts.DataBind(); |
if (ddlContacts.SelectedIndex == -1) { ddlContacts.SelectedIndex = 0; } |
int contactUserID = 0; |
Int32.TryParse(ddlContacts.SelectedValue, out contactUserID); |
_dt = AFPI.Inventory.DAL.StoredProcedureCallerClasses.RetrievalProcedures.ProductUserEmailMatrix(contactUserID); |
if (_dt.Rows.Count == 0) |
{ |
RadGrid1.Visible = false; |
lblNoRecords.Visible = true; |
lblNoRecords.Text = string.Format("<font color=\"red\">Missing Information!</font><br />There are no users setup for {0}!<br /><br />Please <a href=\"EditContactUser.aspx?c={1}\">add</a> at least one user to setup user based emails settings.<br /><br />If every inventory notification will go to the same person <a href=\"EditContacts.aspx\">edit</a> the customer's To, CC and BCC settings.", ddlContacts.SelectedItem.Text, ddlContacts.SelectedValue); |
return; |
} |
lblNoRecords.Visible = false; |
RadGrid1.Visible = true; |
DataRow row = _dt.Rows[0]; |
List<DataColumn> columnsToDelete = new List<DataColumn>(); |
for (int i = 0; i < _dt.Columns.Count; i++) |
{ |
if (row[i].ToString().Length == 0) |
{ |
columnsToDelete.Add(_dt.Columns[i]); |
} |
} |
foreach (DataColumn dc in columnsToDelete) |
{ |
_dt.Columns.Remove(dc); |
} |
//Set the edit indexes of the grid so they show up in edit mode for the number of rows we are using. |
for (int i = 0; i < _dt.Rows.Count; i++) |
{ |
RadGrid1.EditIndexes.Add(i); |
} |
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "RemoveContactUserRecIds", "RemoveContactUserRecIds();", true); |
} |
//if AddMapping = false you should remove mapping. |
[WebMethod] |
public static void ChangeMapping(int ProductID, int UserID, bool AddMapping) { |
Guid? currentUserGuid = UserUtil.getCurrentUserGuid(Membership.GetUser()); |
DateTime moment = DateTime.Now; |
ProductEventEmailTargetMapEntity mapping = null; |
ProductEventEmailTargetMapCollection existingEvents = new ProductEventEmailTargetMapCollection(); |
PredicateExpression f = new PredicateExpression(); |
f.Add(ProductEventEmailTargetMapFields.ContactUserRecId == UserID); |
f.AddWithAnd(ProductEventEmailTargetMapFields.ProductRecId == ProductID); |
if (existingEvents.GetDbCount(f) == 0) |
{ |
mapping = new ProductEventEmailTargetMapEntity(); |
mapping.ContactUserRecId = UserID; |
mapping.ProductRecId = ProductID; |
mapping.ProductEventType = "Any"; |
mapping.CreatedBy = currentUserGuid; |
mapping.CreatedDate = moment; |
} |
else |
{ |
existingEvents.GetMulti(f); |
mapping = existingEvents[0]; |
} |
if (AddMapping) |
{ |
mapping.DeletedBy = null; |
mapping.DeletedDate = null; |
} |
else |
{ |
mapping.DeletedDate = moment; |
mapping.DeletedBy = currentUserGuid; |
} |
mapping.ModifiedBy = currentUserGuid; |
mapping.ModifiedDate = moment; |
mapping.Save(); |
} |
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) |
{ |
//Change the first column to readonly and bold |
(RadGrid1.MasterTableView.AutoGeneratedColumns[0] as GridBoundColumn).ReadOnly = true; |
(RadGrid1.MasterTableView.AutoGeneratedColumns[0] as GridBoundColumn).ItemStyle.Font.Bold = true; |
//(RadGrid1.MasterTableView.AutoGeneratedColumns[0] as GridBoundColumn).ItemStyle.BackColor = System.Drawing.Color.LightGray; |
//Set width to increase performance large dataset for IE |
(RadGrid1.MasterTableView.AutoGeneratedColumns[0] as GridBoundColumn).HeaderStyle.Width = Unit.Pixel(200); |
(RadGrid1.MasterTableView.AutoGeneratedColumns[0] as GridBoundColumn).ItemStyle.Width = Unit.Pixel(200); |
for (int i = 1; i < RadGrid1.MasterTableView.AutoGeneratedColumns.Length; i++ ) |
{ |
(RadGrid1.MasterTableView.AutoGeneratedColumns[i] as GridCheckBoxColumn).HeaderStyle.Width = Unit.Pixel(100); |
(RadGrid1.MasterTableView.AutoGeneratedColumns[i] as GridCheckBoxColumn).ItemStyle.Width = Unit.Pixel(100); |
(RadGrid1.MasterTableView.AutoGeneratedColumns[i] as GridCheckBoxColumn).ReadOnly = false; |
} |
} |
} |
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
if (_dt == null) return; |
//In order to get the checkboxes on all but the first row we have to recreate the datatable with columns 1 - n to boolean |
//so the autogenerate columns knows to use a checkbox and not a textbox in edit mode. |
//Copy the datatable structure |
DataTable dtToBindTo = _dt.Clone(); |
// Loop through our new datatable setting the columns 1 - n to boolean |
//We have to create a new datatable because once the datatable has data we can't change the datatype of the column |
for (int i = 1; i < _dt.Columns.Count; i++) |
{ |
dtToBindTo.Columns[i].DataType = System.Type.GetType("System.Boolean"); |
} |
//Copy every row of our data to the new boolean table. |
foreach (DataRow row in _dt.Rows) |
{ |
dtToBindTo.ImportRow(row); |
} |
_dt.Dispose(); |
DataView dv = dtToBindTo.DefaultView; |
dv.Sort = "Product"; |
//bind the data to the grid. |
RadGrid1.DataSource = dv; |
} |
protected void RadGrid1_PreRender(object source, EventArgs e) |
{ |
ConvertToActualHeaders(); |
} |
private void ConvertToActualHeaders() |
{ |
foreach (GridEditableItem edititem in RadGrid1.MasterTableView.GetItems(GridItemType.EditItem)) |
{ |
foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) |
{ |
if (col.ColumnType == "GridBoundColumn") |
{ |
if (edititem.IsInEditMode) |
{ |
Literal txtbx = edititem[col.UniqueName].Controls[1] as Literal; |
string[] productValues = txtbx.Text.Split('_'); |
txtbxtxtbx.Text = txtbx.Text.Replace("_" + productValues[productValues.Length - 1], ""); |
} |
} |
} |
} |
} |
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) |
{ |
GridDataItem dataItem = (GridDataItem)e.Item; |
int numCols = RadGrid1.MasterTableView.AutoGeneratedColumns.Length; |
string productColumn = DataBinder.Eval(dataItem.DataItem, "Product").ToString(); |
int productID = 0; |
string[] productColumnproductColumnArray = productColumn.Split('_'); |
if (!Int32.TryParse(productColumnArray[productColumnArray.Length - 1], out productID)) |
{ |
return; |
} |
for (int i = 1; i < numCols; i++) |
{ |
CheckBox chk = dataItem[(RadGrid1.MasterTableView.AutoGeneratedColumns[i] as GridCheckBoxColumn).UniqueName].Controls[0] as CheckBox; |
string columnHeader = (RadGrid1.MasterTableView.AutoGeneratedColumns[i] as GridCheckBoxColumn).HeaderText; |
string[] userDataArray = columnHeader.Split('_'); |
int userId = 0; |
if (Int32.TryParse(userDataArray[userDataArray.Length - 1], out userId)) |
{ |
chk.Attributes.Add("onclick", String.Format("checkboxClick({0}, {1}, this);", productID, userId)); |
} |
} |
} |
} |