473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GRIDVIEW: changing column attributes

I have a gridview with some boundfields and buttonfields, and based on the
user's role I want to modify their attributes: for example, if the person's
role doesnt allow updates, I want to set a buttonfields visible attribute to
"false". I know how to get data values from a clicked column, but I havent
been able to find out how to modify the columns such as in the above scenario
when the gridview loads.
Any help is very appreciated.
May 8 '06 #1
2 2059
If you use a TemplateField instead of a BoundField for the columns that you
wish to change its visibility based on the user role then you can write
something like this:
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# Bind("OrderDate", "{0:d}") %>'
Visible='<%=SomeProtectedFunctionThatReturnsBool() '></asp:Label>
</ItemTemplate>

where SomeProtectedFunctionThatReturnsBool would be a function in your
codebehind that decide whether the user has access of not.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"MarkAurit" wrote:
I have a gridview with some boundfields and buttonfields, and based on the
user's role I want to modify their attributes: for example, if the person's
role doesnt allow updates, I want to set a buttonfields visible attribute to
"false". I know how to get data values from a clicked column, but I havent
been able to find out how to modify the columns such as in the above scenario
when the gridview loads.
Any help is very appreciated.

May 8 '06 #2
Mark,

In addition to Phillip's answer, I think that you could do something like
this: Set up a RowDataBound event handler for your GridView. You can then
set the visible attribute of a buttonfield like this:

Button button = (Button)e.Row.Cells[1].Controls[0];
button.Attributes.Add("visible", "false");

Of course, the index that you use to access the right cell will vary
depending on the layout of your grid. I used Cells[1] just as an example.

--Rob Roberts

"MarkAurit" <Ma*******@discussions.microsoft.com> wrote in message
news:E5**********************************@microsof t.com...
I have a gridview with some boundfields and buttonfields, and based on the
user's role I want to modify their attributes: for example, if the
person's
role doesnt allow updates, I want to set a buttonfields visible attribute
to
"false". I know how to get data values from a clicked column, but I
havent
been able to find out how to modify the columns such as in the above
scenario
when the gridview loads.
Any help is very appreciated.

May 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
3
by: Rob Roberts | last post by:
Is there any way to add attributes to GridView ButtonFields? I'm looking for a way to add event handlers to ButtonFields. With regular ASP.NET buttons, I can add event handlers by using the...
1
by: spitapps | last post by:
I have a gridview declaratively added to my webform. This gridview displays data from a stored procedure returned as a dataset. Once the dataset has been modified slightly i bind it to my...
2
by: rodchar | last post by:
hey all, you know in the gridView quick task menu how you have the option of taking a bound column and converting it into a TemplateColumn. Alright, once i do that i goto edit the template column...
0
by: landesjoe | last post by:
Hi, here's my problem in short: Text boxes in gridview don't seem to hold their value if the column's .Visible property is changed back and forth. I've got a form with a gridview populated from...
4
by: Mark Olbert | last post by:
I'm running into a well-described issue in the ASPNET model that I haven't found a good work around for. I have a GridView to which I dynamically add data-bound TemplateFields at run-time. The...
4
by: tirath | last post by:
hi, I want to display data in on my web page, in gridview in this format: Group A Group B A1 A2 B1 B2 Test 1 1 2 1 2 Test 2 1 2 1 2 Group A is header to columns A1 and A2...
0
by: teejayem | last post by:
I am new to asp.net. I have a grid view that is bound to a dataview. I have used a small javascript to select the rows in the gridview see below:- <script language="javascript"...
3
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I have a gridview that uses a sqldatasource. The rows of the gridview are editable. When the gridview is in edit mode, one of the columns is a dropdown. In testing the editing, I deleted the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.