0

i have datagrid and inside which i have a checkbox . now i want this check to be hidden at page load. my code is :

<asp:datagrid id="dgDates" OnItemCommand="gridEventHandler" BorderColor="Black" BorderWidth="1px"
CellPadding="3" runat="server" AutoGenerateColumns="False" HorizontalAlign="Left" AllowSorting="True"
OnSortCommand="SortData" OnItemDataBound="gridItemDataBound">
<HeaderStyle Font-Underline="True" Font-Bold="True" HorizontalAlign="Center" ForeColor="Black"
    BackColor="#D4D0C8"></HeaderStyle>
<Columns>
    <asp:BoundColumn DataField="strParameterName" SortExpression="strParameterName" HeaderText="Parameter Name"></asp:BoundColumn>
    <asp:BoundColumn DataField="dtParameterValue" SortExpression="dtParameterValue" HeaderText="Parameter Value"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Constant" SortExpression="blnStatic" ItemStyle-HorizontalAlign="Center">
        <ItemTemplate>
            <asp:CheckBox ID="cbStaticRolling" Checked="False" Runat="server" ></asp:CheckBox>
        </ItemTemplate>
    </asp:TemplateColumn>
</Columns>
Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
Ram Singh
  • 6,664
  • 35
  • 100
  • 166

2 Answers2

1

Handle the ItemDataBound event

public void gridItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || 
            e.Item.ItemType == ListItemType.AlternatingItem)
        {
            CheckBox cbStaticRolling= (CheckBox)e.Item.FindControl("cbStaticRolling");
            cbStaticRolling.Visible = false;
        }
    }
Agustin Meriles
  • 4,866
  • 3
  • 29
  • 44
  • Is there an ItemDataBound event for the GridView? [I don't see it in the events on MSDN](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx#events). Perhaps you mean [RowDataBound](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx)? – Josh Darnell Oct 14 '11 at 12:31
  • No, for GridView there is not. But the question it's about the old DataGrid – Agustin Meriles Oct 14 '11 at 13:00
  • 1
    thanks man! I was writing the answer for RowDataBound originally, but then I figured out that it was about DataGrid =) – Agustin Meriles Oct 14 '11 at 13:07
0
<asp:CheckBox ID="cbStaticRolling" Checked="False" Visible="False" Runat="server" >
Sean Taylor
  • 4,948
  • 8
  • 25
  • 27
  • I m using this datagrid to show dyna content for a particular content i dont want to display this check box. – Ram Singh Oct 14 '11 at 12:17