asp.net GridView Kolon Gizleme
aspsnippets de gezerken kod yazımını beğendiğim bir yazıyı sizlere paylaşmak isterim.
https://www.aspsnippets.com/Articles/Dynamically-Show-Hide-TemplateField-column-in-ASPNet-GridView-using-C-and-VBNet.aspx
sitesinden alntıdır.
https://www.aspsnippets.com/Articles/Dynamically-Show-Hide-TemplateField-column-in-ASPNet-GridView-using-C-and-VBNet.aspx
sitesinden alntıdır.
HTML Markup
<asp:CheckBox ID="chkCountry" Text="Show Hide Country" runat="server" OnCheckedChanged="OnCheckedChanged"
AutoPostBack="true" Checked="true" />
<hr />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:TemplateField HeaderText="Country" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label Text='<%# Eval("Country") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
AutoPostBack="true" Checked="true" />
<hr />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:TemplateField HeaderText="Country" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label Text='<%# Eval("Country") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
Yorumlar
Yorum Gönder