locked
Radio button in HTML table cells using asp .net RRS feed

  • Question

  • I have a application which fetches data from database and displays the data on a ASP page using VB as follows. The function GetPageData() returns data from database in a table form.

    I now need to add two more columns (Details & History) in this table, which are radio buttons for each row and when user clicks the radio button, a new page should open displaying details or history page depending upon radio button clicked.

    Below is the existing code. Could anyone help me understand how I can achieve this. I am new to .NET & frontend programming.

    Private Sub Build()
        Dim htmlTable As New StringBuilder
        Dim data As New DataTable
        data = GetPageData()  ''Returns data from database
    
        If Not data Is Nothing And Also data.Rows.Count > 0 Then
            htmlTable.Append("<table style='text-align:center;' cellpadding='3' cellspacing='0' style = 'width:100%;' class='clsTable1' id = 'tblMain1' ")
            htmlTable.Append("   > ")
            BuildHeader(htmlTable)
            BuildBody(htmlTable, data)
            htmlTable.Append("</tr>")
            htmlTable.Append("</table><br><br>")
            tblBody.Rows(0).Cells(0).InnerHtml = htmlTable.ToString
        Else
            lblMessage.Text = "No data found"
            tblBody.Rows(0).Cells(0).InnerHtml = lblSpace.Text
    	End If
    End Sub
    
    Private Sub CreateHeaderRow(ByRef htmlTable As StringBuilder)
        Try
            htmlTable.Append("<tr bgcolor='#D3D3D3' style='font-weight:bold;' >")
            htmlTable.Append(" <td align='center'> Customer ID</td>")
            htmlTable.Append(" <td align='center'> Customer Name</td>")
            htmlTable.Append(" <td align='center'> Customer Address</td>")
            htmlTable.Append(" <td align='center'> Details</td>")   'New Column Header for radio button
            htmlTable.Append(" <td align='center'> History</td>")   'New Column Header for radio button
            htmlTable.Append("</tr>")
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    
    Public Sub CreateTableBody(ByRef htmlTable As StringBuilder, ByRef data As DataTable)
        Dim iRow As Integer
        Dim iCol As Integer
        Dim colData As String = String.Empty
        Try
            For iRow = 0 To data.Rows.Count - 1
                For iCol = 0 To data.Columns.Count - 1
                    colData = data.Rows(iRow).Item(iCol).ToString
                    If colData = String.Empty Then
                        htmlTable.Append("&nbsp;")
                    Else
                        htmlTable.Append(colData)
                    End If
                    htmlTable.Append("</td>")
                Next
    
            htmlTable.Append("</tr>")
            Next
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Thanks

    • Moved by Reed KimbleMVP Monday, May 21, 2018 11:44 AM asp.net in vb language
    Monday, May 21, 2018 2:32 AM

Answers

All replies

  • ASP.Net has their own Forums ASP.Net Forums which should be able to assist you.

    La vida loca

    Monday, May 21, 2018 2:41 AM
  • Note on a couple of things:

    1) Learn how to program on the client-side too using JavaScript at the browser and JavaScript plugins, like jQuery, Bootstrap.JS, Angular.JS, Knockout.js, Ajax and many other JavaScript plugins. It's more to it than just knowing how to do server-side programming with VB.NET and the codebehind file. 

    2) Know how to implement SoC with using layered or n-tier.  

    https://msdn.microsoft.com/en-us/library/ee658117.aspx

    https://msdn.microsoft.com/en-us/library/bb384398.aspx?f=255&MSPPError=-2147217396

    3) Learn how to use SoD by using MVC or MVP with MVP being used for Web forms.

    https://www.codeproject.com/Articles/228214/Understanding-Basics-of-UI-Design-Pattern-MVC-MVP

    https://msdn.microsoft.com/en-us/library/ff649571.aspx

    4) Learn how to not use datasets and datatables, but rather, learn how to use straight-up ADO.NET, MS SQL Server command objects, parametrized inline T-SQL,  parametrized stored procedure, a datareader, custom object like a DTO as an individual object or collection of objects in a List(of T). Or figure out how to use that ADO.NET Entity Framework.

    Resources such as memory on Web server is finite and speed is at a premium too. 

    https://dzone.com/articles/reasons-move-datatables

    http://lauteikkehn.blogspot.com/2012/03/datatable-vs-list.html

    https://www.codeguru.com/vb/gen/vb_misc/oop/article.php/c7063/Data-Transfer-Object-Pattern-Goes-VBNET.htm

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/auto-implemented-properties

    The benefits are the same for VB or C# concerning the DTO.

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    You can post to the ASP.NET forums that have already been mentioned.

    http://forums.asp.net/

    Monday, May 21, 2018 4:46 AM