Hi,
I have a WHDG with a 3 level (tables) dataset, Autogenerate columns true. My grid displays fine, 3 band, columns and data are visible. Now I would like to format columns (hide, color, etc...) after binding them.Tried these in DataBound or simply just after calling DataBind()
grid3.GridView.Columns["Check"].Header.Text = "";grid3.Columns["Check"].Header.Text = "";
but my Columns collection is always empty. Why is that?
Thank you
Update: I realized I have to set AutoGenerateColumns to false but cannot figure out in which event. InitializeBand..?
Hi onlien,
Thank you for posting in our forum.
You can set the AutoGenerateColumns from the markup or in code-behind in InitializeBand event. If it is set to false, you should have the columns added in the aspx. To access the columns of child band, you should use the following syntax:
WebHierarchicalDataGrid1.GridView.Band.Bands[0].Columns["ID"].Hidden = true;
The GridView.Band is the top-level band of the grid.
Let me know if you have any questions regarding this matter.
Hello onlien,
I would suggest you to use the InitializeBand event for this kind of operations.
Feel free to contact me if you have any further questions.
Hi Nikolay,
Now I have problems with a command button. I implemented a template column with an imagebutton (after this article : http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/WebDataGrid_Using_Item_Template.html)
In InitializeBand I have:
tdf = new TemplateDataField();tdf.Key = "Restart";
(e.Band.Columns.FromKey("Restart") as TemplateDataField).ItemTemplate = new RestartItemTemplate();
I bind the data on every page load so the above code should run and re-create my button every time.Still, the button is only displayed when I initially call the page. After postback it is gone and OnItemCommand is never firing (I added OnItemCommand="Chain_OnItemCommand" in aspx).
Q1: Why is it not firing, when should I re-create the template?
Q2: How do I give a commandArgument? Template class:
public class RestartItemTemplate : ITemplate { public void InstantiateIn(Control container) { ImageButton btnRestart = new ImageButton(); btnRestart.ImageUrl = "~/images/smallicons/delete16.png"; btnRestart.CommandName = "Restart"; btnRestart.CommandArgument = " # I need my ID here - cannot access in initializeBand! #"; container.Controls.Add(btnRestart); } }
It works from aspx but I need it from code.
<ig:TemplateDataField Key="Restart" > <ItemTemplate > <asp:ImageButton ID="btnRestart" runat="server" ImageUrl="~/restart16.gif" CommandArgument='<%# Eval("Id") %>' CommandName="Restart" /> </ItemTemplate> </ig:TemplateDataField>
Hi online,
I would suggest you to apply the ItemTemplate to your column on page load:
TemplateDataField templateColumn1 = (TemplateDataField)WebDataGrid1.Columns["TemplateColumn1"];
templateColumn1.ItemTemplate = new RestartItemTemplate();
You can set the CommandArgument using the following syntax:
btnRestart.CommandArgument = ((DataRowView)((TemplateContainer)container).DataItem)["ID"].ToString();
Please refer to the attached sample and let me know if you have any questions.
Finally I added itemtemplate in InitializeBand:(e.Band.Columns.FromKey("Restart") as TemplateDataField).
ItemTemplate = new RestartItemTemplate();I was struggling some more with adding commandArgument in InitializeRow but this one worked for me after I realized I forgot to set the ID property to "btnRestart" of my imagebutton in InstantiateIn: ImageButton btnRestart = e.Row.Items[0].FindControl("btnRestart") as ImageButton; // (if button is in 1st column)btnRestart.CommandArgument = e.Row.Items.FindItemByKey("Id").Value.ToString(); Thanks again for your help--
Thanks for your reply. I'm glad you solved your issue.
Let me know if you have any other questions.