Bind Session value to HTML Table in ASPX page using C# and VB.Net

Last Reply one month ago By dharmendr

Posted one month ago

Hello All,

I am working on Dashborad I am struck on one issue.

I have session value in comma separted but my requirement is i am trying to bind that session value in separted value on each string to html each individual td values.

but below session value i am getting comman separated values i need to bind each td values has a separated values

please help me how to bind each td.

My code :

<table style="width: 100%;" border="1">
    <tr>
        <th style="text-align: center;">JobNames</th>
    </tr>
    <tr>
        <td><%= Session("JobNamesSucces").ToString%></td>
        <td></td>
    </tr>
</table>

Thanks

Anand

You are viewing reply posted by: dharmendr one month ago.
Posted one month ago Modified on one month ago

Hi anand.mand,

Check this example. Now please take its reference and correct your code.

HTML

C#

<table style="width: 100%;" border="1">
    <tr>
        <th style="text-align: center;">
            JobNames
        </th>
    </tr>
    <%if (Session["JobNamesSucces"] != null)
        {
            for (int i = 0; i < Session["JobNamesSucces"].ToString().Split(',').Length; i++)
            {%>
    <tr>
        <td>
            <%=Session["JobNamesSucces"].ToString().Split(',')[i]%>
        </td>
    </tr>
    <%}
            } %>
</table>

VB.Net

<table style="width: 100%;" border="1">
    <tr>
        <th style="text-align: center;">
            JobNames
        </th>
    </tr>
    <%If Session("JobNamesSucces") IsNot Nothing Then
            For i As Integer = 0 To Session("JobNamesSucces").ToString().Split(","c).Length - 1%>
    <tr>
        <td>
            <%=Session("JobNamesSucces").ToString().Split(","c)(i)%>
        </td>
    </tr>
    <% Next
    End If%>
</table>

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    Session["JobNamesSucces"] = "Developer,Tester,DBDesigner";
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Session("JobNamesSucces") = "Developer,Tester,DBDesigner"
End Sub

Screenshot