Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a developed gridview with the link buttons as Modify, Remove and other columns as Id,Name, Email Address, Username etc.

My problem is, if the Name ="Primary" then Modify and Remove link buttons should be invisible for that row only, for other rows those buttons should be visible. Please suggest me how to do this, please send me the code samples.
I am using the following code:
C#
if (tempContact.Primary==true)
{
System.Web.UI.WebControls.LinkButton remove = System.Web.UI.WebControls.LinkButton)e.Row.Cells[4].FindControl("lkbEmailRemove"); 
remove.Visible = false;
}


But is it removing the link button for all other rows also.

Its kind of urgent.

Appreciate your quick response.

Thanks,
Nag
Posted
Updated 8-Aug-12 8:13am
v2
Comments
[no name] 8-Aug-12 12:33pm    
"kind of urgent"? I checked my schedule and it's not urgent at all.
Christian Amado 8-Aug-12 14:15pm    
@Wes Aday May be you can reschedule your activities. hahaha

You can use RowDataBound event and there you can disable the button that you need.

See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound[^]

Hope it helps. Let me know if you need more assistance.
 
Share this answer
 
Comments
Pankaj Nikam 8-Aug-12 13:26pm    
Perfect :) +5 :)
ureachnag 8-Aug-12 14:08pm    
Christin Amado,

Thanks for you swift response. I have used the following code.

if (tempContact.Primary==true)
{
System.Web.UI.WebControls.LinkButton remove = System.Web.UI.WebControls.LinkButton)e.Row.Cells[4].FindControl("lkbEmailRemove");
remove.Visible = false;
}

but it is removing the linkbutton for all the rows.
Appreciate your response.

Thanks,
Nag
Christian Amado 8-Aug-12 14:14pm    
@ureachnag yeap. You need to add your logic inside that event =)
ureachnag 8-Aug-12 14:25pm    
Christian Amado,

Can you help me to write the logic please. From last 2 days I am struggling to find the solution.

Thanks is advance,
Nag
ureachnag 8-Aug-12 17:22pm    
Thanks @ __TR__,
your solution worked for me. Appreciated your help.
@Christian Amado: Thank you very much for your help.

--Nag
The below link should give you an idea on how to do it

hide-disable-commandfield-gridview[^]
 
Share this answer
 
Comments
Christian Amado 8-Aug-12 17:23pm    
Nice!
Volynsky Alex 8-Aug-12 19:18pm    
yes,nice!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900