DYNAMICALLY CREATING HTML AND ASP ELEMENTS FROM CODE BEHIND

Hugh Jackman

Total Post:51

Points:359
Posted by  Hugh Jackman
C#  HTML5 
 1387  View(s)
Ratings:
Rate this:

I am filling a DataTable in the code behind my webpage and trying to use it to create a "p" tag which has text of the service option followed by an ASPxCheckBox. Problem that I'm having is that I can't seem to get them within the same line, they are separated. Any assistance would be greatly. 

The code so far: 

        Dim dtExample As New DataTable
        dtExample.Columns.Add("ID")
        dtExample.Columns.Add("Option")
        dtExample.Columns.Add("Price", GetType(Decimal))
        dtExample.Rows.Add({1, "Engine Flush", 99.95})
        dtExample.Rows.Add({2, "Oil Check", 19.95})
        dtExample.Rows.Add({3, "Pump Up Tires", 9.95})
        dtExample.Rows.Add({4, "Air Conditioner", 69})
        dtExample.Rows.Add({5, "Brake Fluid Checker", 49.95})  
        For Each row As DataRow In dtExample.Rows
            Dim cb As New DevExpress.Web.ASPxEditors.ASPxCheckBox
            Dim ParaElement As New HtmlGenericControl 
            ParaElement.InnerHtml = "<p class='serviceoption center' id='" & row("ID") & "'>" & row("Option") & "</p>"
            cb.ID = row("ID")
            cb.Checked = False
            cb.Visible = True
            cb.ClientInstanceName = row("ID")
            serviceoptions.Controls.Add(ParaElement)
            serviceoptions.Controls.Add(cb)
        Next

  1. Norman Reedus

    Post:45

    Points:315
    Re: Dynamically creating HTML and asp elements from code behind

    Devexpress controls can be difficult to style in some cases. Rather than wrapping your checkboxes within a p tag, I would suggest setting the CssClass property of the AspxCheckboxto a CSS class containing your styling, and setting the descriptive text of the checkbox by using the Text property rather than a p tag.

  1. David Miller

    Post:30

    Points:210
    Re: Dynamically creating HTML and asp elements from code behind

    a P is a paragraph, if memory serves me right that will always be on a new line. 

    I suspect you want something like this but using css instead of the inline styles shown below 

    <div style="float:left;margin-right:10px;">Your Text</div>
    <div style="float:left;clear:right;">Your Checkbox</div>

      Modified On Apr-07-2018 02:29:14 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!