Need help with adding button to a datagrid dynamically

M

Mark

Hello, I have a need to add a button column to a datagtrid, below is my code
and although it does not produce an error, it also does not work, any help?
I'm hoping that I can capture the button click in the datagrid itemcommand
event but figure having the button show first would be a good thing. I can
get a hyperlink column to show with no problem but it causes the page to
refresh which is what I'm trying to avoid.

Thanks for any help.

Mark

Public Sub LoadAddresses()

'Set up the DataTable

Dim oadd As Sterling_by.customermanagerLLBL.clsAddress

Dim NewRow As System.Data.DataRow = m_datatable.NewRow()

m_datatable = New DataTable("TableName")

m_datatable.Columns.Add(New System.Data.DataColumn("Address ID"))

m_datatable.Columns.Add(New System.Data.DataColumn("Street"))

m_datatable.Columns.Add(New System.Data.DataColumn("City"))

m_datatable.Columns.Add(New System.Data.DataColumn("State"))

m_datatable.Columns.Add(New System.Data.DataColumn("Zipcode"))

For Each oadd In oIndiv.oAddresses

AddAddressRow(oadd.AddressId.ToString, oadd.Street.ToString,
oadd.City.ToString, oadd.State.ToString, oadd.ZipCode.ToString)

Next

'Set up the datagrid control

dbgIndividualAddresses.DataSource = m_datatable

dbgIndividualAddresses.DataBind()

End Sub

Private Sub AddAddressRow(ByVal sCol0 As String, ByVal sCol1 As String,
ByVal sCol2 As String, ByVal scol3 As String, ByVal sCol4 As String)

Dim NewRow As System.Data.DataRow = m_datatable.NewRow()

' this one doesn't work, nothing shows up

NewRow(0) = "<asp:button id=" + Chr(34) + "btn" + sCol0 + Chr(34) + "
runat=" + Chr(34) + "server " + Chr(34) + "cssclass=" + Chr(34) + "button" +
Chr(34) + " text=" + Chr(34) + "Edit" + Chr(34) + "></asp:button>"

' This row works okay but causes a reload of the data when clicked which is
what I'm trying to get around.

'NewRow(0) ="<a href=individualinfo.aspx?addressid=" + sCol0 + ">Edit</a>"

NewRow(1) = sCol1

NewRow(2) = sCol2

NewRow(3) = scol3

NewRow(4) = sCol4

m_datatable.Rows.Add(NewRow)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top