I have a grid as follows. On first click it sorts one way. Than when I click on the arrow, the next column gets the sort arrow instead!
class AssignBanGridCtrl : WebControl
{
#region Fields
private RadAjaxLoadingPanel _RadLoadingPanel = new RadAjaxLoadingPanel();
private UpdatePanel _UpdatePanel = new UpdatePanel();
private RadGrid _RadGrid1 = new RadGrid();
private PriceDealProductBanTable _PriceDealProductBanTable = new PriceDealProductBanTable();
private PriceDealProposal _Proposal = null;
private GXButton _btnCopyToSelect = new GXButton();
private GXButton _btnSaveSelected = new GXButton();
private GXTextBox _TbBAN = new GXTextBox();
public SmartOrderQuote OrderQuote;
private string _BanColumnName;
private string _ServiceColumnName;
#endregion
#region Constructors
public AssignBanGridCtrl(PriceDealProposal proposal, bool hasOrderRequest)
: base()
{
}
#endregion
#region Overrides
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this._ProductTable = new _ProductTable().ExecuteTypedDataTable();
this._RadLoadingPanel.ID = "_RadLoadingPanel";
this._RadLoadingPanel.Transparency = 30;
this._RadLoadingPanel.Skin = "WebBlue";
this._RadLoadingPanel.BackgroundPosition = AjaxLoadingPanelBackgroundPosition.Center;
this.Controls.Add(this._RadLoadingPanel);
#region Grid1
this._RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
this._RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
this._RadGrid.ID = "RadGrid1";
this._RadGrid.Skin = "WebBlue";
this._RadGrid.Width = Unit.Percentage(100);
this._RadGrid.GridLines = GridLines.None;
this._RadGrid.PageSize = 100;
this._RadGrid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
this._RadGrid.AllowPaging = true;
this._RadGrid.AutoGenerateColumns = false;
this._RadGrid.EnableLinqExpressions = false;
this._RadGrid.AllowAutomaticInserts = false;
this._RadGrid.AllowAutomaticUpdates = false;
this._RadGrid.AllowAutomaticDeletes = false;
if(this._ProductTable.Count>=100)
this._RadGrid1.AllowFilteringByColumn = true;
this._RadGrid1.AllowSorting = true;
this._RadGrid1.MasterTableView.AllowNaturalSort = false;
this._RadGrid1.MasterTableView.DataKeyNames = new string[] { this._ProductTable.PriceDealEntityProductItemIdColumn.ColumnName };
this._RadGrid1.MasterTableView.ClientDataKeyNames = new string[] { this._ProductTable.PriceDealEntityProductItemIdColumn.ColumnName };
this._RadGrid1.EnableLinqExpressions = false;
this._RadGrid1.MasterTableView.NoMasterRecordsText = "No Products found.";
this._RadGrid1.MasterTableView.Width = Unit.Percentage(100);
this._RadGrid1.ClientSettings.Selecting.AllowRowSelect = true;
this._RadGrid1.ClientSettings.Selecting.UseClientSelectColumnOnly = true;
this._RadGrid1.AllowMultiRowSelection = true;
this._RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
this._RadGrid1.ItemDataBound += RadGrid1_ItemDataBound;
this._RadGrid1.ItemCreated += RadGrid1_ItemCreated;
GridBoundColumn boundColumn = new GridBoundColumn();
string columnName;
#region RadGrid Columns
GridClientSelectColumn selectAll = new GridClientSelectColumn();
selectAll.UniqueName = "SelectOne";
this._RadGrid1.MasterTableView.Columns.Add(selectAll);
string templateColumnName;
GridTemplateColumn templateColumn = new GridTemplateColumn();
columnName = this._ProductTable.SupplementalOriginalPriceDealEntityProductItemIdColumn.ColumnName; ;
boundColumn = new GridBoundColumn();
boundColumn.DataField = columnName;
boundColumn.UniqueName = "SupplementalOriginalPriceDealEntityProductItemId";
boundColumn.Display = false;
this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
columnName = this._ProductTable.IsCustomProductColumn.ColumnName; ;
boundColumn = new GridBoundColumn();
boundColumn.DataField = columnName;
boundColumn.UniqueName = "IsCustomProduct";
boundColumn.Display = false;
this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
columnName = this._ProductTable.SupplementalActionCodeColumn.ColumnName; ;
boundColumn = new GridBoundColumn();
boundColumn.DataField = columnName;
boundColumn.UniqueName = "SupplementalActionCode";
boundColumn.Display = false;
this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
columnName = this._ProductTable.IsLockedColumn.ColumnName; ;
boundColumn = new GridBoundColumn();
boundColumn.DataField = columnName;
boundColumn.UniqueName = "IsLocked";
boundColumn.Display = false;
this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
columnName = this._ProductTable.DescriptionColumn.ColumnName; ;
boundColumn = new GridBoundColumn();
boundColumn.DataField = columnName;
boundColumn.HeaderText = "Location";
boundColumn.UniqueName = "Location";
boundColumn.SortExpression = columnName;
this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
columnName = this._ProductTable.CatalogProductColumn.ColumnName;
boundColumn = new GridBoundColumn();
boundColumn.FilterTemplate = new DropdownTemplate(columnName, _RadGrid1, this._ProductTable.SelectDistinct(columnName));
boundColumn.DataField = columnName;
boundColumn.HeaderText = "Product";
boundColumn.UniqueName = "Product";
boundColumn.AllowFiltering = true;
boundColumn.SortExpression = columnName;
this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
columnName = this._ProductTable.CountryColumn.ColumnName;
boundColumn = new GridBoundColumn();
boundColumn.FilterTemplate = new DropdownTemplate(columnName, _RadGrid1, this._ProductTable.SelectDistinct(columnName));
boundColumn.DataField = columnName;
boundColumn.HeaderText = "Country";
boundColumn.UniqueName= "Country";
boundColumn.AllowFiltering = true;
boundColumn.SortExpression = columnName;
this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
columnName = this._ProductTable.StateColumn.ColumnName;
boundColumn = new GridBoundColumn();
boundColumn.FilterTemplate = new DropdownTemplate(columnName, _RadGrid1, this._ProductTable.SelectDistinct(columnName));
boundColumn.DataField = columnName;
boundColumn.HeaderText = "State/Province";
boundColumn.UniqueName = "StateProvince";
boundColumn.AllowFiltering = true;
boundColumn.SortExpression = columnName;
this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
columnName = this._ProductTable.SourceSystemTypeDescriptionColumn.ColumnName;
boundColumn = new GridBoundColumn();
boundColumn.FilterTemplate = new DropdownTemplate(columnName, _RadGrid1, this._ProductTable.SelectDistinct(columnName));
boundColumn.DataField = columnName;
boundColumn.HeaderText = "OE System";
boundColumn.UniqueName = "OESystem";
boundColumn.SortExpression = columnName;
boundColumn.AllowFiltering = true;
this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
templateColumn = new GridTemplateColumn();
_BanColumnName = this._ProductTable.BillingAccountNumberColumn.ColumnName;
templateColumn.DataField = _BanColumnName;
templateColumn.ItemTemplate = new TextBoxTemplate(_BanColumnName);
templateColumn.HeaderText = "BAN";
templateColumn.UniqueName = "BAN";
templateColumn.AllowFiltering = false;
this._RadGrid1.MasterTableView.Columns.Add(templateColumn);
if (IsSupplementOrChangeQuote)
{
_ServiceColumnName = this._ProductTable.AssetServiceIdColumn.ColumnName;
templateColumn = new GridTemplateColumn();
templateColumn.ItemTemplate = new TextBoxTemplate(_ServiceColumnName);
templateColumn.DataField = _ServiceColumnName;
templateColumn.HeaderText = "Asset/Service ID";
templateColumn.UniqueName = "AssetServiceID";
templateColumn.AllowFiltering = false;
this._RadGrid1.MasterTableView.Columns.Add(templateColumn);
}
#endregion
#endregion
this._UpdatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional;
this._UpdatePanel.ContentTemplateContainer.Controls.Add(this._RadGrid1);
this._TbBAN.ID = "TbBAN";
this._TbBAN.ShowTitle = true;
this._TbBAN.MaxLength = 30;
this._TbBAN.WikiKeyword = "Assignment";
this._TbBAN.Title = "BAN :";
this._UpdatePanel.ContentTemplateContainer.Controls.Add(this._TbBAN);
this._btnCopyToSelect.ID = "BtCopyToSelected";
this._btnCopyToSelect.Text = "Copy To Selected";
this._btnCopyToSelect.ToolTip = "This will save the BAN above to all selected items.";
this._btnCopyToSelect.CssClass = "GxButtonBlue";
this._btnCopyToSelect.Click += new EventHandler(BtnCopyToSelected_Click);
this._UpdatePanel.ContentTemplateContainer.Controls.Add(this._btnCopyToSelect);
this._btnSaveSelected.ID = "BtSaveToSelected";
this._btnSaveSelected.Text = "Save Selected";
this._btnSaveSelected.CssClass = "GxButtonBlue";
this._btnSaveSelected.Click += new EventHandler(BtSaveToSelected_Click);
this._UpdatePanel.ContentTemplateContainer.Controls.Add(this._btnSaveSelected);
this.Controls.Add(this._UpdatePanel);
this._btnCopyToSelect.OnClientClick = "OnClientClick('" + _RadGrid1.ClientID + "')";
this._btnSaveSelected.OnClientClick = "OnClientClick('" + _RadGrid1.ClientID + "')";
}
private void BtnCopyToSelected_Click(object sender, EventArgs e)
{
}
void BtSaveToSelected_Click(object sender, EventArgs e)
{
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
}
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
RadTextBox txtBan = (RadTextBox)dataItem.FindControl(_BanColumnName);// pass the TextBox ID
txtBan.Attributes.Add("onfocus", "SelectRow('" + dataItem.ItemIndex + "','" + _RadGrid1.ClientID + "')");
}
}
#endregion
void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
try
{
this._ProductTable = new _ProductTable().ExecuteTypedDataTable();
}
catch (Exception) { }
this._RadGrid1.DataSource = this._ProductTable;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(Page);
if (ajaxManager != null)
ajaxManager.AjaxSettings.AddAjaxSetting(this._UpdatePanel, this._RadGrid1, this._RadLoadingPanel);
}
}
}