The grid that I’m using inherits the Infragistics.Web.UI.GridControls.WebDataGrid. The version of Infragistics is 2010 volume 3.
I want to create an ITemplate for my inherited WebDataGrid which contains a button. I add a click event on this button and the button displays itself very well on the WebDataGrid. When I click on a button in the grid it generates a postback and that's where my issue begins.
I'd selected one row and clicked on the button but when I debug my codebehind during the postback it states: "Behaviors.Selection.SelectedRows" have a count of 0. It seems that when I click the button on my inherited WebDataGrid it looses the selected rows collection.
The template looks like this:
public class Cx_DatagridTemplateButton : ITemplate
{
Button _oButton;
/// <summary>
/// Delegate event method click
/// </summary>
public delegate void click();
/// This is the instance of the deligate method. These instance will run if we click on the button
public click ClickEvent;
/// Wen a datarow is initialized
/// <param name="container"></param>
public virtual void InstantiateIn(Control container)
this._oButton = new Button();
this._oButton.ID = "btnButton";
this._oButton.Width = Unit.Percentage(100);
this._oButton.Height = Unit.Percentage(100);
this._oButton.Click += delegate(object dlgSender, EventArgs dlgE)
this.ClickEvent();
};
container.Controls.Add(_oButton);
}
With the following manner I add the button column to the WebDataGrid (when there is no postback):
Cx_DatagridTemplateButton template = new Cx_DatagridTemplateButton();
Infragistics.Web.UI.GridControls.TemplateDataField column = new Infragistics.Web.UI.GridControls.TemplateDataField();
column.Header.Text = "Button";
column.ItemTemplate = template;
column.Key = "tempCol";
column.Width = System.Web.UI.WebControls.Unit.Pixel(60);
this.Cx_Datagrid1.Columns.Add(column);
this.Cx_Datagrid1.DataBind();
template.ClickEvent += new Cx_DatagridTemplateButton.click(_Default_Click);
Session.Add("tempCol", template);
When there is a postback:
((Infragistics.Web.UI.GridControls.TemplateDataField)this.Cx_Datagrid1.Columns[0]).ItemTemplate = (Cx_DatagridTemplateButton)Session["tempCol"];
The problem I had before this issue was the fact that my button disappeared when the page had a postback. Therefore I enclosed the template in a session object to retrieve it again when the postback is handled.
The method I use for (_Default_Click) looks like:
public void _Default_Click()
System.Diagnostics.Debug.WriteLine("Selected rows: " + Cx_Datagrid1.Behaviors.Selection.SelectedRows.Count);
When I debug this code, I get the total count of the selectedrows is 0.If I put it in my page_load the selected rows are 0 also.The strange thing is when I place a click event on a different control on my page which generates a postback then the code DOES display the selected rows as it should be.
How can I resolve this that I can use the ITemplate Button on my inherited WebDataGrid so I can access the selected rows on the codebehind (server) when a button is clicked.
Thanks for answering
Hi Jerry,
Please note that custom implementations and modifications of Infragistics controls are not supported by our Developer Support engineers. Our support policy is available at:
https://www.infragistics.com/support/support-policies
Please do not hesitate to contact me if you have any questions.
Best Regards,
Petar IvanovDeveloper Support EngineerInfragistics, Inc.https://www.infragistics.com/support