Hi nedash,
I have created sample. Refer the below code.
HTM
<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false" OnRowDataBound="RowDataBound">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Show" HeaderText="Show" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Code" HeaderText="Code" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="PLLink" Text="Link" runat="server" />
<asp:LinkButton ID="PLBuy" Text="Buy" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Id"), new DataColumn("Show"), new DataColumn("Name"), new DataColumn("Code") });
dt.Rows.Add(1, "Buy", "Waterfall", 1111);
dt.Rows.Add(2, "Download", "Waterfall", 1111);
dt.Rows.Add(3, "Download and Buy", "Green", 2222);
Session["Order"] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton PLLink = e.Row.FindControl("PLLink") as LinkButton;
LinkButton PLBuy = e.Row.FindControl("PLBuy") as LinkButton;
if (Session["Order"] != null)
{
DataTable dt = Session["Order"] as DataTable;
if (dt.Rows.Count > 0)
{
if (dt.Rows[e.Row.RowIndex]["show"].ToString().ToLower() == "buy")
{
PLLink.Visible = false;
PLBuy.Visible = true;
}
else if (dt.Rows[e.Row.RowIndex]["show"].ToString().ToLower() == "download")
{
PLLink.Visible = true;
PLBuy.Visible = false;
}
else if (dt.Rows[e.Row.RowIndex]["show"].ToString().ToLower() == "download and duy")
{
PLLink.Visible = false;
PLBuy.Visible = true;
}
}
}
}
}
Screenshot
Id | Show | Name | Code | |
1 |
Buy |
Waterfall |
1111 |
Buy |
2 |
Download |
Waterfall |
1111 |
Link |
3 |
Download and Buy |
Green |
2222 |
Link Buy |