Hi kid.live,
Please refer below sample.
Note: For this sample i have used temporary DataTable. For more details refer Dynamically create DataTable and bind to GridView in ASP.Net.
HTML
<asp:GridView runat="server" CssClass="table table-striped table-bordered" Width="100%" ID="gvDetails" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField ShowHeader="false" HeaderText="المبلغ<br/>Amount">
<ItemTemplate>
<asp:Label ID="lblamount" runat="server" Text='<%# Eval("amount") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="branch_num" ItemStyle-HorizontalAlign="Center" HtmlEncode="false" HeaderText="رقم المحطة<br/>Branch No" />
<asp:BoundField DataField="machineID" ItemStyle-HorizontalAlign="Center" HtmlEncode="false" HeaderText="رقم المكينة<br/>Machine ID" />
<asp:BoundField DataField="shift" ItemStyle-HorizontalAlign="Center" HtmlEncode="false" HeaderText="جدول<br/>Shifts" />
<asp:BoundField DataField="userID" ItemStyle-HorizontalAlign="Center" HtmlEncode="false" HeaderText="المستخدم<br/>User" />
<asp:BoundField DataField="voucher_date" ItemStyle-HorizontalAlign="Center" HtmlEncode="false" HeaderText="تاريخ الفاتورة<br/>Voucher Date" />
<asp:BoundField DataField="voucher_number" ItemStyle-HorizontalAlign="Center" HtmlEncode="false" HeaderText="رقم الفاتورة<br/>Voucher No" />
<asp:TemplateField ShowHeader="false">
<HeaderTemplate>
<asp:Label ID="lblHeadPrint" runat="server" Text="<br/>Print" Visible="true"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkIBPrint" CommandName="Select" CommandArgument="<%# Container.DataItemIndex %>"
CssClass="btn btn-outline-dark rounded-circle" runat="server" Visible="true" OnClick="lnkIBPrint_Click">
<i class="bi bi-printer"></i>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageField Visible="false"></asp:ImageField>
</Columns>
<PagerStyle HorizontalAlign="Center" CssClass="GridPager" />
<HeaderStyle HorizontalAlign="Center" />
</asp:GridView>
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[7] {
new DataColumn("amount"),
new DataColumn("branch_num"),
new DataColumn("machineID"),
new DataColumn("shift"),
new DataColumn("userID"),
new DataColumn("voucher_date"),
new DataColumn("voucher_number")});
dt.Rows.Add("10000", "421031", "MC102", "10am", "Rough1010", "10/02/2020", "101240");
gvDetails.DataSource = dt;
gvDetails.DataBind();
}
}
protected void lnkIBPrint_Click(object sender, EventArgs e)
{
.gvDetails.Columns[7].Visible = false;
gvDetails.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(6) {New DataColumn("amount"), New DataColumn("branch_num"), New DataColumn("machineID"), New DataColumn("shift"), New DataColumn("userID"), New DataColumn("voucher_date"), New DataColumn("voucher_number")})
dt.Rows.Add("10000", "421031", "MC102", "10am", "Rough1010", "10/02/2020", "101240")
gvDetails.DataSource = dt
gvDetails.DataBind()
End If
End Sub
Protected Sub lnkIBPrint_Click(ByVal sender As Object, ByVal e As EventArgs)
gvDetails.Columns(7).Visible = False
gvDetails.DataBind()
End Sub