Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Dynamic ButtonColumn in datagrid?

Thread Tools

Dynamic ButtonColumn in datagrid?

Posts: n/a
Hi all

I've been looking at dynamicallly adding a ButtonColumn in a datagrid
by implementing ITemplate. The datagrid has been designed as a
usercontrol. I don't yet have the skill to know how to deal with the
events so that an event can been seen on the hosting page. I've
scoured the net for examples of how to do this but there doesn't seem
to be much demand for it. Does anyone know of an example I could
follow, or know how to do it?

Any help much appreciated.


For what it's worth, here is what I've done so far, which is to get
the column to show:

'method in usercontrol called by hosting page in Page_Load event
Public Sub BoundButtonColumnAdd()
Dim bcb As New TemplateColumn
bcb.ItemTemplate = New ButtonTemplate("col")
End Sub

Public Class ButtonTemplate
Implements ITemplate
Private mColName As String

Public Sub New(ByVal ColName As String)
mColName = ColName
End Sub

Public Overridable Overloads Sub InstantiateIn(ByVal Container As
Control) Implements ITemplate.InstantiateIn

Dim oButton As Button = New Button
oButton.ID = mColName.Replace(" ", "")
oButton.Text = mColName

AddHandler oButton.DataBinding, AddressOf BindControl
AddHandler oButton.Click, AddressOf ButtonClick


End Sub

Public Sub BindControl(ByVal Sender As Object, ByVal E As

Dim oButton As Button = CType(Sender, Button)
Dim oContainer As DataGridItem =
'setting the button text to a particular column value
'(this is uncomplete but is roughly what I want to do)
If oContainer.DataItem(mColName).GetType.ToString =
oButton.Text = ""
oButton.Text = oContainer.DataItem(mColName)
End If
End Sub

Public Sub ButtonClick(ByVal Sender As Object, ByVal E As

'seems to me that I should raise a click event here

End Sub
End Class
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ButtonColumn Roger ASP .Net 1 01-23-2004 03:54 AM
DataGrid ButtonColumn/BoundColumn problem John ASP .Net 3 11-03-2003 02:20 PM
Enabling/Disabling a DataGrid ButtonColumn CGuy ASP .Net 2 10-22-2003 05:43 PM
Dynamic separator row causing ButtonColumn event wiring problems zigjog ASP .Net Datagrid Control 0 09-29-2003 04:36 PM
How to use ButtonColumn to select a Datagrid row? Northern ASP .Net 0 07-22-2003 08:34 PM