Access Control in ItemTemplate

J

Jonathan Wood

I have a GridView control with one column a TemplateField that contains two
buttons. I'd like to hide one or both button based on the row number.

Can anyone provide some tips on how I can do this?

Thanks.
 
E

Eliyahu Goldin

Handle PreRender event for the gridview. In the event loop through the Rows
collection. For every row use Cells collection to locate the column. Once on
the column, use FindControl method to locate controls inside the template.

Button btn = myGridView.Rows.Cells[j].FindControl(myButton1) as Button;

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
J

Jonathan Wood

Thanks!

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Eliyahu Goldin said:
Handle PreRender event for the gridview. In the event loop through the
Rows collection. For every row use Cells collection to locate the column.
Once on the column, use FindControl method to locate controls inside the
template.

Button btn = myGridView.Rows.Cells[j].FindControl(myButton1) as Button;

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Jonathan Wood said:
I have a GridView control with one column a TemplateField that contains
two buttons. I'd like to hide one or both button based on the row number.

Can anyone provide some tips on how I can do this?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top