DataGrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a datagrid and there are 2 columns where I may or may not want to print based upon a condition.

I thought I could use the OnItemCreated Event and then turn the visibility flag on or off as the condition required, but I can not seem to be able to find and turn on the visibility property.

Here is how these controls are defined in my grid (they are the 6th and 7th columns in my datagrid)....

public void dgCalendarOnItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control ctrl = e.Item.Controls[5];
ctrl.Visible=true;
ctrl = e.Item.Controls[6];
ctrl.Visible = true;
}
}
<asp:TemplateColumn HeaderText="Product Data Mgr<br>Cut-Off Date" Visible="False">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"PDM_CUTOFF_PERIOD") %>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Product Data Mgr<br>Cut-Off Time" Visible="False">
<ItemTemplate>
<%# DataBinder.EvaContainer.DataItem,"PDM_CUTOFF_PERIOD_Time") %>
</ItemTemplate>
</asp:TemplateColumn>

this does not make my column visible.

Any ideas on what I must do to turn these columns visibility property to "true"
 
Jim Heavey said:
I have a datagrid and there are 2 columns where I may or may not want to print based upon a condition.

I thought I could use the OnItemCreated Event and then turn the visibility
flag on or off as the condition required, but I can not seem to be able to
find and turn on the visibility property.
Here is how these controls are defined in my grid (they are the 6th and
7th columns in my datagrid)....
public void dgCalendarOnItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control ctrl = e.Item.Controls[5];
ctrl.Visible=true;
ctrl = e.Item.Controls[6];
ctrl.Visible = true;
}
}

Jim,

First of all, I suggest you use a subject line which is more descriptive. I
almost didn't read your message.

Second of all, if I were you, I'd make sure of which controls I had ahold of
in [6] and [5]. Make sure that you're looking at the controls you really
want.

Also, why not simply use "dataGrid.Columns[n].Visible = false;" ?
 
Back
Top