473,327 Members | 1,896 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,327 software developers and data experts.

Is that possible to add some server script to DataGrid?

hi, all
I just got a question here when I am using the datagrid, my code like this:
<asp:DataGrid id="DataGridBanner" runat="server" style=....>
.....
<Columns>
<% if(m_adUser.IsWebMaster()) { %>
<asp:EditCommandColumn Visible='<%# m_adUser.IsWebMaster()%>'
ButtonType="PushButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<% } %>
.......
because I only want to show the edit button to web master.
But when I run it, it shows up an error and says, " Code blocks are not
supported in this context", So, can i do this in this page, or I must write
another similar page especially for web master?

Thanks
Nov 19 '05 #1
4 1153
You don't need any ifs. You need just to databinding Visible property, that
is what you are already trying to do.

<Columns>
<asp:EditCommandColumn Visible='<%# IsWebMaster %>'
ButtonType="PushButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>

IsWebMaster should be a protected or public property of your page class. It
should return true if the user is the web master.

Eliyahu

"Nicky" <Ni***@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.com...
hi, all
I just got a question here when I am using the datagrid, my code like this: <asp:DataGrid id="DataGridBanner" runat="server" style=....>
....
<Columns>
<% if(m_adUser.IsWebMaster()) { %>
<asp:EditCommandColumn Visible='<%# m_adUser.IsWebMaster()%>'
ButtonType="PushButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<% } %>
......
because I only want to show the edit button to web master.
But when I run it, it shows up an error and says, " Code blocks are not
supported in this context", So, can i do this in this page, or I must write another similar page especially for web master?

Thanks

Nov 19 '05 #2
You can also handle the DataGrid's ItemDataBound event. The e.Item passed
as a parameter is the row that was just populated. You can then manipulate
the controls in that row.

-Brock
DevelopMentor
http://staff.develop.com/ballen
You don't need any ifs. You need just to databinding Visible property,
that is what you are already trying to do.

<Columns>
<asp:EditCommandColumn Visible='<%# IsWebMaster %>'
ButtonType="PushButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
IsWebMaster should be a protected or public property of your page
class. It should return true if the user is the web master.

Eliyahu

"Nicky" <Ni***@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.com...
hi, all
I just got a question here when I am using the datagrid, my code like

this:
<asp:DataGrid id="DataGridBanner" runat="server" style=....>
....
<Columns>
<% if(m_adUser.IsWebMaster()) { %>
<asp:EditCommandColumn Visible='<%# m_adUser.IsWebMaster()%>'
ButtonType="PushButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<% } %>
......
because I only want to show the edit button to web master.
But when I run it, it shows up an error and says, " Code blocks are
not
supported in this context", So, can i do this in this page, or I must

write
another similar page especially for web master?

Thanks


Nov 19 '05 #3
thanks,
I found some fields, it works. But for gernal gound column, like this:
<asp:BoundColumn Visible='<%# IsWebMaster %>' DataField="CreatorID"
HeaderText="CreatorID"></asp:BoundColumn>
it says:
CS0117: 'System.Web.UI.WebControls.BoundColumn' does not contain a
definition for 'DataBinding'
I think this is reasonale. So probably I have to convert it to template and
do it like others columns. Or move all of this logic to the data bind event
routine.

"Eliyahu Goldin" wrote:
You don't need any ifs. You need just to databinding Visible property, that
is what you are already trying to do.

<Columns>
<asp:EditCommandColumn Visible='<%# IsWebMaster %>'
ButtonType="PushButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>

IsWebMaster should be a protected or public property of your page class. It
should return true if the user is the web master.

Eliyahu

"Nicky" <Ni***@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.com...
hi, all
I just got a question here when I am using the datagrid, my code like

this:
<asp:DataGrid id="DataGridBanner" runat="server" style=....>
....
<Columns>
<% if(m_adUser.IsWebMaster()) { %>
<asp:EditCommandColumn Visible='<%# m_adUser.IsWebMaster()%>'
ButtonType="PushButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<% } %>
......
because I only want to show the edit button to web master.
But when I run it, it shows up an error and says, " Code blocks are not
supported in this context", So, can i do this in this page, or I must

write
another similar page especially for web master?

Thanks


Nov 19 '05 #4
So try changing it to Templates
and use DataGrid's ItemDataBound event by manipulating the e.item.
That could save your time.
Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #5

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

Similar topics

4
by: DM | last post by:
Is there any way, using a server control, to execute a routine (say, add record to database) and then close the browser window. I'm having a difficult time doing this using a master\detail model...
1
by: Ryan McLean | last post by:
Hi everyone! What is happening is the method: sub_btnSubmitClicked is being executed every time any other object with a Handler is executed. I am trying not to use the withevents and handles...
1
by: Martin | last post by:
Hello Group I'm having a bit of trouble figuring this out. I'm grateful for any hints. Let's assume I'm have a webapplication with two .aspx pages, Page A and Page B. Page A consists of a...
2
by: Ing. Rajesh Kumar | last post by:
Hi everybody Is it possible to set the size of text boxes when in edit mode ? Thanks in advance Raja
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
by: toddw607 | last post by:
Hi Everyone! I have a ASP.NET webform that brings data in from SQL Server 2000 and displays it on a page. I want to update the webpage while in IE using the following code: <%@ Import...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.