Hi
I have a ultragrid with some column created dinamically.
In particular, I have a column with ImageButton.
If I create ImageButton from aspx then the ItemCommand fires correctly, while when I create a ImageButton from code cs
the event ItemCommand doesn't fires.
Anyone can you help me?
Thanks
Luca
Hello Luca,
Most probably this is a page lifecycle issue -- the columns you create dynamically needs to be created prior trigerring the event -- my guess here is that you may need to move the column creating code as earlier in the lifecycle as possible -- OnInit is best.
For more information on ASP.NET page lifecylce please follow this link
http://msdn.microsoft.com/en-us/library/ms178472.aspx
but I create columns already in Page_Init
Can you please paste some sample code -- how do you create the columns dynamically? It will be much easier for us to provide a solution / assist if we are able to reproduce it locally.
Thanks.
Hello I created a page sample
In the Prova.aspx, I declare a UltraWebGrid
<igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" OnItemCommand="UltraWebGrid1_ItemCommand" > </igtbl:UltraWebGrid>
In the Prova.aspx.cs, create column in Page_Init and define UltraWebGrid1_ItemCommand for itemcommand event
protected void Page_Init(object sender, EventArgs e) { UltraGridColumn ugc = new UltraGridColumn(); ugc.Key = "gc"; ugc.BaseColumnName = "test"; ugc.Header.Caption = "test"; ugc.Header.Title = "test"; UltraWebGrid1.Columns.Add(ugc); TemplatedColumn tc = new TemplatedColumn(); TestUltraGridCommandTemplate ugt = new TestUltraGridCommandTemplate(); tc.CellTemplate = ugt; tc.Key = "tc"; UltraWebGrid1.Columns.Add(tc); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { UltraGridRow row = new UltraGridRow(); UltraGridCell cell = new UltraGridCell(); cell.Value = "test"; row.Cells.Add(cell); UltraWebGrid1.Rows.Add(row); } } protected void UltraWebGrid1_ItemCommand(object sender, Infragistics.WebUI.UltraWebGrid.UltraWebGridCommandEventArgs e) { Response.Redirect("www.google.it"); }
Finally I use a class TestUltraGridCommandTemplate to create a Column with a Template containing ImageButton
public class TestUltraGridCommandTemplate : System.Web.UI.ITemplate{ public TestUltraGridCommandTemplate() { } public void InstantiateIn(System.Web.UI.Control container) { ImageButton editButton; editButton = new ImageButton(); editButton.ID = "aaaa"; editButton.AlternateText = "text"; editButton.SkinID = "DetailDocument"; editButton.CommandName = "Edit"; container.Controls.Add(editButton); }}
Than ks for the help
Is there anyone can help me?
Thaks
Thanks for the answer.
I try it.
However, now I transformed templatecolumn with the image button in standard UltragridColumn with type button.inserting the image as background
With UltraGridColumn of type button I used the client event ClickCellButton to handle the button click and than postback the grid.