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
InitialiseControl routine. This adds a clsImageButtonColumn column to my
grid with "Edit" as the command name.
If this button is clicked then DataGrid1_ItemCommand 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.clsImageInfo =
m_objImage_ROC("List_Edit")
Dim objEC As New clsImageButtonColumn("Edit", objImageInfo)
'"../images/Edit.ICO")
With objEC
.HeaderStyle.Width = Unit.Pixel(25)
.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
End With
DataGrid1.Columns.Add(objEC)
End Sub
'=================================================
'Custom DataGrid Control - Edit event
'=================================================
Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.ItemCommand
Dim intID As Integer = CType(e.Item.FindControl("lblID"),
Label).Text
Select Case e.CommandName
Case "Edit"
RaiseEvent Edit(intID)
Case "Delete"
RaiseEvent Delete(intID)
End Select
End Sub
'=================================================
'clsImageButtonColumn
'=================================================
Public Class clsImageButtonColumn
'Inherits System.Web.UI.UserControl
Inherits System.Web.UI.WebControls.DataGridColumn
Private m_strCommandName As String
'Private m_strImageURL As String
Private m_objImageInfo As clsImage_ROC.clsImageInfo
Private Sub New()
End Sub
Public Sub New(ByVal CommandName As String, ByVal objImageInfo As
clsImage_ROC.clsImageInfo)
m_strCommandName = CommandName
m_objImageInfo = objImageInfo
End Sub
Public Overrides Sub InitializeCell(ByVal cell As TableCell, ByVal
columnIndex As Integer, ByVal itemType As ListItemType)
MyBase.InitializeCell(cell, columnIndex, itemType)
If ((itemType <> ListItemType.Header) And (itemType <>
ListItemType.Footer)) Then
Dim ctl As WebControl = Nothing
Dim ibt As ImageButton = New
System.Web.UI.WebControls.ImageButton
ibt.ImageUrl = m_objImageInfo.Url ' m_strImageURL
ibt.AlternateText = m_objImageInfo.AltText
ibt.CommandName = m_strCommandName
ctl = ibt
cell.HorizontalAlign = HorizontalAlign.Center
cell.Controls.Add(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.)