|
 |
aspx thread: Making a Button control visible/hidden within a Datagrid?
Message #1 by "Oliver, Wells" <WOliver@l...> on Wed, 17 Jul 2002 08:38:46 -0700
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C22DA8.0A0BB410
Content-Type: text/plain;
charset="iso-8859-1"
I have a datagrid displaying some data (bulletin board posts). Within each
row, I have a button which allows editing of that data.
However, I want only the users who made the post to have the button
displayed on that row. The user's name is in the session and is also a
column in the datagrid, so I can match the two strings to determine whether
or not to display the Edit button for that row.
Any ideas? Thanks.
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Wed, 17 Jul 2002 12:00:02 -0400
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C22DAB.02976910
Content-Type: text/plain;
charset="ISO-8859-1"
Wells,
The easiest (nasty) way to do this is to add a <% %> block in your
ItemTemplate to do a test:
<% If (SomeCondition) %>
<asp:Button RunAt="server" />
<% End If %>
Of course if you want to distance yourself from crappy ASP stuff, then
you'll want to not have any blocks of <% %> in your *.aspx files at all. To
do this, you'll need to hook the ItemCreated event of the DataGrid, and
using the arguments passed to the event (the event fires every time a new
row is added to the data grid, among other things) you can test and see if a
condition is met for the current row to show or hide the <asp:Button> you
have in your <ItemTemplate>.
HTH,
- Chuck
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Wednesday, July 17, 2002 11:39 AM
To: ASP+
Subject: [aspx] Making a Button control visible/hidden within a Datagrid?
I have a datagrid displaying some data (bulletin board posts). Within each
row, I have a button which allows editing of that data.
However, I want only the users who made the post to have the button
displayed on that row. The user's name is in the session and is also a
column in the datagrid, so I can match the two strings to determine whether
or not to display the Edit button for that row.
Any ideas? Thanks.
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com <http://www.levitonvoicedata.com>
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
Message #3 by "Oliver, Wells" <WOliver@l...> on Wed, 17 Jul 2002 15:06:25 -0700
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C22DDE.3126EF20
Content-Type: text/plain;
charset="iso-8859-1"
Excellent idea.. One question. I've written this subroutine:
Public Sub ShowButton (S as System.Object, E as DataListItemEventArgs)
E.Item.FindControl ("editButton").Visible = False
End Sub
It's not exactly working-- I have a Button control with the id of
"editButton" w/in the DataList. How can I edit the properties of that button
from w/in that subroutine?
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 17, 2002 9:00 AM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Datagr
id?
Wells,
The easiest (nasty) way to do this is to add a <% %> block in your
ItemTemplate to do a test:
<% If (SomeCondition) %>
<asp:Button RunAt="server" />
<% End If %>
Of course if you want to distance yourself from crappy ASP stuff, then
you'll want to not have any blocks of <% %> in your *.aspx files at all. To
do this, you'll need to hook the ItemCreated event of the DataGrid, and
using the arguments passed to the event (the event fires every time a new
row is added to the data grid, among other things) you can test and see if a
condition is met for the current row to show or hide the <asp:Button> you
have in your <ItemTemplate>.
HTH,
- Chuck
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Wednesday, July 17, 2002 11:39 AM
To: ASP+
Subject: [aspx] Making a Button control visible/hidden within a Datagrid?
I have a datagrid displaying some data (bulletin board posts). Within each
row, I have a button which allows editing of that data.
However, I want only the users who made the post to have the button
displayed on that row. The user's name is in the session and is also a
column in the datagrid, so I can match the two strings to determine whether
or not to display the Edit button for that row.
Any ideas? Thanks.
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com <http://www.levitonvoicedata.com>
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
Message #4 by Feduke Cntr Charles R <FedukeCR@m...> on Thu, 18 Jul 2002 09:25:34 -0400
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C22E5E.98A1CFA0
Content-Type: text/plain;
charset="ISO-8859-1"
Is it throwing an error on your .Visible line, or is it just not causing
anything visual to happen?
- Chuck
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Wednesday, July 17, 2002 6:06 PM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Da tagr
id?
Excellent idea.. One question. I've written this subroutine:
Public Sub ShowButton (S as System.Object, E as DataListItemEventArgs)
E.Item.FindControl ("editButton").Visible = False
End Sub
It's not exactly working-- I have a Button control with the id of
"editButton" w/in the DataList. How can I edit the properties of that button
from w/in that subroutine?
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 17, 2002 9:00 AM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Datagr
id?
Wells,
The easiest (nasty) way to do this is to add a <% %> block in your
ItemTemplate to do a test:
<% If (SomeCondition) %>
<asp:Button RunAt="server" />
<% End If %>
Of course if you want to distance yourself from crappy ASP stuff, then
you'll want to not have any blocks of <% %> in your *.aspx files at all. To
do this, you'll need to hook the ItemCreated event of the DataGrid, and
using the arguments passed to the event (the event fires every time a new
row is added to the data grid, among other things) you can test and see if a
condition is met for the current row to show or hide the <asp:Button> you
have in your <ItemTemplate>.
HTH,
- Chuck
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Wednesday, July 17, 2002 11:39 AM
To: ASP+
Subject: [aspx] Making a Button control visible/hidden within a Datagrid?
I have a datagrid displaying some data (bulletin board posts). Within each
row, I have a button which allows editing of that data.
However, I want only the users who made the post to have the button
displayed on that row. The user's name is in the session and is also a
column in the datagrid, so I can match the two strings to determine whether
or not to display the Edit button for that row.
Any ideas? Thanks.
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com <http://www.levitonvoicedata.com>
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
Message #5 by "Oliver, Wells" <WOliver@l...> on Thu, 18 Jul 2002 08:12:27 -0700
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C22E6D.86F28970
Content-Type: text/plain;
charset="iso-8859-1"
Yeah, I get an error:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
I'm assuming this should be easy, but I'm just not sure where to go. Turning
off a button with the id of "editButton" when the ITemCreated event is
fired..
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Thursday, July 18, 2002 6:26 AM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Da tagr
id?
Is it throwing an error on your .Visible line, or is it just not causing
anything visual to happen?
- Chuck
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Wednesday, July 17, 2002 6:06 PM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Da tagr
id?
Excellent idea.. One question. I've written this subroutine:
Public Sub ShowButton (S as System.Object, E as DataListItemEventArgs)
E.Item.FindControl ("editButton").Visible = False
End Sub
It's not exactly working-- I have a Button control with the id of
"editButton" w/in the DataList. How can I edit the properties of that button
from w/in that subroutine?
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 17, 2002 9:00 AM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Datagr
id?
Wells,
The easiest (nasty) way to do this is to add a <% %> block in your
ItemTemplate to do a test:
<% If (SomeCondition) %>
<asp:Button RunAt="server" />
<% End If %>
Of course if you want to distance yourself from crappy ASP stuff, then
you'll want to not have any blocks of <% %> in your *.aspx files at all. To
do this, you'll need to hook the ItemCreated event of the DataGrid, and
using the arguments passed to the event (the event fires every time a new
row is added to the data grid, among other things) you can test and see if a
condition is met for the current row to show or hide the <asp:Button> you
have in your <ItemTemplate>.
HTH,
- Chuck
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Wednesday, July 17, 2002 11:39 AM
To: ASP+
Subject: [aspx] Making a Button control visible/hidden within a Datagrid?
I have a datagrid displaying some data (bulletin board posts). Within each
row, I have a button which allows editing of that data.
However, I want only the users who made the post to have the button
displayed on that row. The user's name is in the session and is also a
column in the datagrid, so I can match the two strings to determine whether
or not to display the Edit button for that row.
Any ideas? Thanks.
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com <http://www.levitonvoicedata.com>
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
Message #6 by Feduke Cntr Charles R <FedukeCR@m...> on Thu, 18 Jul 2002 11:36:35 -0400
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C22E70.E66EC870
Content-Type: text/plain;
charset="ISO-8859-1"
Try putting it in an If... Then block:
If e.Item.FindControl("editButton") Is Not Nothing Then ' is that how you do
!= null in VB?
e.Item.FindControl("editButton").Visible = False
End If
Of course keep in mind that FindControl is going to cost you a performance
hit if you you're using it for EVERY item created. Take a look at the
DataGridEventArgs and first check and see what item type the e variable is
before trying to FindControl (i.e. if its header or footer then you don't
need to check).
- Chuck
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Thursday, July 18, 2002 11:12 AM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Da tagr
id?
Yeah, I get an error:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
I'm assuming this should be easy, but I'm just not sure where to go. Turning
off a button with the id of "editButton" when the ITemCreated event is
fired..
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Thursday, July 18, 2002 6:26 AM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Da tagr
id?
Is it throwing an error on your .Visible line, or is it just not causing
anything visual to happen?
- Chuck
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Wednesday, July 17, 2002 6:06 PM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Da tagr
id?
Excellent idea.. One question. I've written this subroutine:
Public Sub ShowButton (S as System.Object, E as DataListItemEventArgs)
E.Item.FindControl ("editButton").Visible = False
End Sub
It's not exactly working-- I have a Button control with the id of
"editButton" w/in the DataList. How can I edit the properties of that button
from w/in that subroutine?
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 17, 2002 9:00 AM
To: ASP+
Subject: [aspx] RE: Making a Button control visible/hidden within a Datagr
id?
Wells,
The easiest (nasty) way to do this is to add a <% %> block in your
ItemTemplate to do a test:
<% If (SomeCondition) %>
<asp:Button RunAt="server" />
<% End If %>
Of course if you want to distance yourself from crappy ASP stuff, then
you'll want to not have any blocks of <% %> in your *.aspx files at all. To
do this, you'll need to hook the ItemCreated event of the DataGrid, and
using the arguments passed to the event (the event fires every time a new
row is added to the data grid, among other things) you can test and see if a
condition is met for the current row to show or hide the <asp:Button> you
have in your <ItemTemplate>.
HTH,
- Chuck
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Wednesday, July 17, 2002 11:39 AM
To: ASP+
Subject: [aspx] Making a Button control visible/hidden within a Datagrid?
I have a datagrid displaying some data (bulletin board posts). Within each
row, I have a button which allows editing of that data.
However, I want only the users who made the post to have the button
displayed on that row. The user's name is in the session and is also a
column in the datagrid, so I can match the two strings to determine whether
or not to display the Edit button for that row.
Any ideas? Thanks.
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com <http://www.levitonvoicedata.com>
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to
Message #7 by "Mingkun Goh" <mangokun@h...> on Thu, 18 Jul 2002 20:47:39
|
|
Here is some sample code which I hope can be of use to you.
Dim CurUserName As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CurUserName = Session("UserName")
If Not Page.IsPostBack Then
' Get the list of users from a web service
DsUsers1 = ws.GetUsers()
DataGrid1.DataBind()
End If
End Sub
Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
DataList1.ItemDataBound
' Match the two strings to determine whether
' the current user is the one who made this post
If dsUsers.Tables(0).Rows(e.Item.ItemIndex)("UserName") <>
CurUserName Then
If Not IsNothing(e.Item.FindControl("btnEdit")) Then
' Cast the control to its specific type
Dim buttonEdit As Button = CType(e.Item.FindControl
("btnEdit"), Button)
' Change any of its properties
buttonEdit.Visible = False
End If
End If
End Sub
btnEdit will be the id of the button in the DataList Item
Template.
Similar usage of the DataList1_ItemDataBound event is also found in these
threads:
<headertemplate> - loadtemplate
http://p2p.wrox.com/archive/aspx/2002-05/96.asp
populating a drop down list from within a datagrid
http://p2p.wrox.com/archive/aspx/2002-05/59.asp
Previous message:
I have a datagrid displaying some data (bulletin board posts). Within each
row, I have a button which allows editing of that data.
However, I want only the users who made the post to have the button
displayed on that row. The user's name is in the session and is also a
column in the datagrid, so I can match the two strings to determine whether
or not to display the Edit button for that row.
Any ideas? Thanks.
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
|
|
 |