How to fill an HTML paragraph with data in ASP .NET Web Forms?

1

I have a page with a paragraph and its styles in HTML. According to the data of a DataSet that I have previously filled with XML I have to fill in some fields of this paragraph.

What is the best way to do it?

<div class ="paragraph">
  <div class="text">
    <p><span style="font-family:'Arial Negrita'; font-weight:700;"> Número ficha: WWWW </span></p>
    <p><span style="font-family:'Arial Negrita'; font-weight:700;"> Nombre: XXXX </span></p>
    <p><span style="font-family:'Arial Negrita'; font-weight:700;"> Apellido: YYYY </span></p>
    <p><span style="font-family:'Arial Negrita'; font-weight:700;"> DNI: ZZZZ </span></p>
  </div>
</div>

Where WWWW , XXXX , YYYY , ZZZZ would be the variables that I read of DataSet For example: WWWW = dataSet.Tables["CLIENTES"].Rows[0]["NumFicha"]

    
asked by Popularfan 28.08.2018 в 13:38
source

1 answer

1

If I understand you correctly, the simplest solution is to wrap your values "WWW", "XXX", "YYY" and "ZZZ" in spans (or another element) with id and runat="server" to be accessible from the server and assign them the value in Page_Load or where needed.

Frontal

<p><span style="font-family:'Arial Negrita'; font-weight:700;"> Número ficha: <span id="spanWWW" runat="server"></span> </span></p>
    <p><span style="font-family:'Arial Negrita'; font-weight:700;"> Nombre: <span id="spanXXX" runat="server"></span> </span></p>
    <p><span style="font-family:'Arial Negrita'; font-weight:700;"> Apellido: <span id="spanYYY" runat="server"></span> </span></p>
    <p><span style="font-family:'Arial Negrita'; font-weight:700;"> DNI: <span id="spanZZZ" runat="server"></span> </span></p>

Codebehind (server)

spanWWW.InnerHtml = dataSet.Tables["CLIENTES"].Rows[0]["NumFicha"]

Note : I do not know if your block HTML will be repeated for each Row of dataSet but in that case you would have to iterate through your dataSet to go assigning values to each block.

    
answered by 28.08.2018 / 14:01
source