Home > Archive > ASP .NET > August 2004 > Need help with adding button to a datagrid dynamically
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Need help with adding button to a datagrid dynamically
|
|
|
|
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
| |
| Thomas Dodds 2004-08-31, 4:01 pm |
| Add a button column and specify the ComandName ...
"Mark" <anon@crl.com> wrote in message
news:uf%23%23%23i2jEHA.3844@TK2MSFTNGP12.phx.gbl...
>
> 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
>
>
>
>
|
|
|
|
|