如何隐藏数据网格内的复选框?

时间:2011-10-14 12:12:15

标签: asp.net datagrid checkbox findcontrol

我有datagrid,里面有一个复选框。现在我希望在页面加载时隐藏此检查。我的代码是:

<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>

2 个答案:

答案 0 :(得分:1)

处理ItemDataBound事件

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;
        }
    }

答案 1 :(得分:0)

<asp:CheckBox ID="cbStaticRolling" Checked="False" Visible="False" Runat="server" >