CSDN博客

img bgu

[我的ASP.net学习历程]DataGrid(DataBind)(2)

发表于2004/9/21 19:46:00  1108人阅读

<%@ Page Language="C#" AutoEventWireup="True" Debug="true" %>
<Script language="C#" runat="server">
void Page_Load(Object Sender,EventArgs e){
 if (!Page.IsPostBack){
  Radio_1.Checked=true;
  }
 Hashtable HT=new Hashtable();
 HT.Add("1234","Microsoft");
 HT.Add("5678","IBM");
 HT.Add("7895","SUN");
 HT.Add("0123","Orlce");
 
 MyDataGrid.DataSource=HT;
 MyDataGrid.DataBind();
}

void RadioClick_2(Object Sender,EventArgs E){
 MyDataGrid.Columns[2].Visible=false;
 Radio_1.Checked=false;
 }
 
void RadioClick_1(Object Sender,EventArgs E){
 MyDataGrid.Columns[2].Visible=true;
 Radio_2.Checked=false;
 }

void RadioClick_3(Object Sender,EventArgs E){
 MyDataGrid.Visible=true;
 Radio_4.Checked=false;
 }

void RadioClick_4(Object Sender,EventArgs E){
 MyDataGrid.Visible=false;
 Radio_3.Checked=false;
}
</Script>
<form runat="server">
<asp:datagrid ID="MyDataGrid" runat="server" AutoGenerateColumns="false" BackColor="#FF0000" ItemStyle-HorizontalAlign="center" ShowFooter="true" FooterStyle-BackColor="#FFFF90" CellPadding="2">
<columns>
 <asp:boundcolumn HeaderText="<strong>Book Code</strong>" ItemStyle-BackColor="#FF9900" DataField="Key"/>
 <asp:boundcolumn HeaderText="<strong>Book Title</strong>" ItemStyle-BackColor="#FF6600" DataField="Value"/>
 <asp:templatecolumn HeaderText="<strong>Check</strong>" ItemStyle-BackColor="#FF9900" ItemStyle-HorizontalAlign="center">
  <itemtemplate>
   <asp:checkbox ID="CheckBox" runat="server"/>
  </itemtemplate>
 </asp:templatecolumn>
 <asp:templatecolumn HeaderText="<strong>Check</strong>" ItemStyle-BackColor="#FF9900" ItemStyle-HorizontalAlign="center">
  <itemtemplate>
   <asp:button ID="Button" Text="Button" runat="server"/>
  </itemtemplate>
 </asp:templatecolumn>
</columns>
</asp:datagrid>
<br>
DataGrid.Columns.Visible:
<asp:radiobutton ID="Radio_1" Text="True" AutoPostBack="true" OnCheckedChanged="RadioClick_1" runat="server"/>
<asp:radiobutton ID="Radio_2" Text="False" AutoPostBack="true" OnCheckedChanged="RadioClick_2" runat="server"/>
<br>
DataGrid.Visible:
<asp:radiobutton ID="Radio_3" Text="True" AutoPostBack="true" OnCheckedChanged="RadioClick_3" runat="server"/>
<asp:radiobutton ID="Radio_4" Text="False" AutoPostBack="true" OnCheckedChanged="RadioClick_4" runat="server"/>
</form>

0 0

相关博文

我的热门文章

img
取 消
img