I have overcome my linkbutton problem by modifying the stored procedure and
it now runs much faster.
I am however interested in using your suggestion for my dynamically created
datagrids. Could you prove some example code to get this to work please.
As previously mentioned, I dynamically add custom columns to my datagrid.
If the grid requires an Edit column then I call AddEditButton in my
InitialiseContr ol routine. This adds a clsImageButtonC olumn column to my
grid with "Edit" as the command name.
If this button is clicked then DataGrid1_ItemC ommand event is fired and
e.CommandName will be "Edit" and I fire my Datagrid's custom Edit event.
Im not sure where I would put the client side script that you are
suggesting.
Terry Holland
'============== =============== =============== =====
'Custom DataGrid Control - Add Edit Button To Grid
'============== =============== =============== =====
Private Sub AddEditButton()
Dim objImageInfo As clsImage_ROC.cl sImageInfo =
m_objImage_ROC( "List_Edit" )
Dim objEC As New clsImageButtonC olumn("Edit", objImageInfo)
'"../images/Edit.ICO")
With objEC
.HeaderStyle.Wi dth = Unit.Pixel(25)
.HeaderStyle.Ho rizontalAlign = HorizontalAlign .Center
End With
DataGrid1.Colum ns.Add(objEC)
End Sub
'============== =============== =============== =====
'Custom DataGrid Control - Edit event
'============== =============== =============== =====
Private Sub DataGrid1_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DataGrid1.ItemC ommand
Dim intID As Integer = CType(e.Item.Fi ndControl("lblI D"),
Label).Text
Select Case e.CommandName
Case "Edit"
RaiseEvent Edit(intID)
Case "Delete"
RaiseEvent Delete(intID)
End Select
End Sub
'============== =============== =============== =====
'clsImageButton Column
'============== =============== =============== =====
Public Class clsImageButtonC olumn
'Inherits System.Web.UI.U serControl
Inherits System.Web.UI.W ebControls.Data GridColumn
Private m_strCommandNam e As String
'Private m_strImageURL As String
Private m_objImageInfo As clsImage_ROC.cl sImageInfo
Private Sub New()
End Sub
Public Sub New(ByVal CommandName As String, ByVal objImageInfo As
clsImage_ROC.cl sImageInfo)
m_strCommandNam e = CommandName
m_objImageInfo = objImageInfo
End Sub
Public Overrides Sub InitializeCell( ByVal cell As TableCell, ByVal
columnIndex As Integer, ByVal itemType As ListItemType)
MyBase.Initiali zeCell(cell, columnIndex, itemType)
If ((itemType <> ListItemType.He ader) And (itemType <>
ListItemType.Fo oter)) Then
Dim ctl As WebControl = Nothing
Dim ibt As ImageButton = New
System.Web.UI.W ebControls.Imag eButton
ibt.ImageUrl = m_objImageInfo. Url ' m_strImageURL
ibt.AlternateTe xt = m_objImageInfo. AltText
ibt.CommandName = m_strCommandNam e
ctl = ibt
cell.Horizontal Align = HorizontalAlign .Center
cell.Controls.A dd(ctl)
End If
End Sub
End Class
2. Still postback, however, we no longer use the LinkButton's Click event
to do the redirection(or other server-side task) because click event of
the Linkbutton require that LinkButton be created again and added into Page's
control collection(this is not possible for your scenario since you do not
want to involve the addtional evaludation and control construction).
Instead, we can put a html input hidden field on the page. And for our
linkbuttons, we can register some client-side onclick script for them,
these script will set the sufficient information in the hidden field.
Then, when the page is postback (because of one of the linkbutton get
clicked), we can programmtically check that hidden field's value(directly
through Request.Forms Collection) and determine what operation to do or
where to redirect , all this is done before the evaluation and control
constructing code. How do you think?
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)