2013-07-10 30 views
1

我有一個gridview,有一對BoundFields英寸。我想要做的是一旦選中(或取消選中)特定複選框<asp:CheckBox ID="chkShowExtra" runat="server" AutoPostBack="True" oncheckedchanged="chkShowExtra_CheckedChanged" Text="Show extra details" Checked="False" />它應該切換幾個BoundFields的可見性。 我該如何做到這一點?在CheckedChanged事件中切換綁定域的可見性

<asp:BoundField DataField="CUS_DatabaseEdition" DataFormatString="" HeaderText="Edition" SortExpression="CUS_DatabaseEdition" Visible="false" /> 
<asp:BoundField DataField="Offices" HeaderText="O" SortExpression="Offices" Visible="false"> 
    <ItemStyle HorizontalAlign="Right" />    
</asp:BoundField> 
<asp:BoundField DataField="CUS_CustomerQuantity" HeaderText="Q" SortExpression="CUS_CustomerQuantity" Visible="false"> 
    <ItemStyle HorizontalAlign="Right" />    
</asp:BoundField> 

我也發現這個事件,我認爲它會派上用場。

protected void chkShowExtra_CheckedChanged(object sender, EventArgs e) 
{ 

} 

謝謝你的幫忙!

回答

0

我用它來切換BoundFields的可見性;

grdCategories.Columns[1].Visible = chkShowExtra.Checked; 
grdCategories.Columns[2].Visible = chkShowExtra.Checked; 
grdCategories.Columns[11].Visible = chkShowExtra.Checked; 

chkShowExtra_CheckedChanged事件中。