ASP.NET - How to find anchor tag in gridview's rowdatabound event

Asked By jyoti yadav on 21-Feb-13 02:51 AM
I have a gridview in which am using anchor tag to open popup on column "A".
and now i have to disable enable anchor tag acc. to my condition. than how can I do it.

Thanx
abdul rehman replied to jyoti yadav on 21-Feb-13 06:13 AM
gridview1.columns[anchorcolumn].visible=false pleace it on load if that column initial should be invisible or
gridview1.columns[0].visible=false if u r  visible or disable or
use property enable=false or true
base on u condition u can set true or false

please mark me
jyoti yadav replied to abdul rehman on 21-Feb-13 07:14 AM
hey abdul thanx for reply,
but i dont want to hide column, i have to hide disable a particular columns value. Have to disable anchor tag link disable.
abdul rehman replied to jyoti yadav on 21-Feb-13 09:23 AM
Hi Jyothi
may i know on what condition base u need
as per ur requirement see below example which i understood just copy and paste in new form and try it

<%



@ Page Language="C#" AutoEventWireup="true" CodeBehind="linkEnable.aspx.cs" Inherits="WebApplication1.linkEnable" %>

<!


DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<


html xmlns="http://www.w3.org/1999/xhtml">

<


head runat="server">



<title></title>



<script type="text/javascript">



function c(par) {

document.getElementById(


'a').enabled = false;



return par;

}





</script>



<style type="text/css">



.GridView1 td:hover

{




background-color:#D8D8D8;



cursor:pointer;



content:normal;



text-decoration:none;

}





</style>

</


head>

<


body>



<form id="form1" runat="server">



<div>

<


asp:gridview ID="Gridview1" CssClass="GridView1" AutoGenerateColumns="false" runat="server"



onrowdatabound="Gridview1_RowDataBound" Width="297px">

<


Columns>

<


asp:TemplateField >

<


ItemTemplate>

<


a href="http://www.google.com" id="a" onclick="return c(false)" >Google</a>

</


ItemTemplate>

</


asp:TemplateField>



<asp:BoundField DataField="a" HeaderText="id" />



<asp:BoundField DataField="b" HeaderText="Name" />

</


Columns>

</


asp:gridview>






</div>



</form>

</


body>

</


html>

.cs file



protected void Page_Load(object sender, EventArgs e)

{




if (!IsPostBack)

{




DataTable dt = new DataTable();

dt.Columns.Add(


"a");

dt.Columns.Add(


"b");



DataRow dr = dt.NewRow();

dr[


"a"] = "1";

dr[


"b"] = "s";

dt.Rows.Add(dr);

dr = dt.NewRow();

dr[



"a"] = "2";

dr[


"b"] = "ss";

dt.Rows.Add(dr);

dr = dt.NewRow();

dr[



"a"] = "3";

dr[


"b"] = "sss";

dt.Rows.Add(dr);

dr = dt.NewRow();

dr[



"a"] = "4";

dr[


"b"] = "ssss";

dt.Rows.Add(dr);

Gridview1.DataSource = dt;

Gridview1.DataBind();




}

}

}

Thanks Regards
ABdul rehman
still any doubt