Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
My java script code-:


VB
<script type="text/javascript">
    function showhead(imagename, itm) {
        debugger;

        document.getElementById("headicon").className = imagename;

        document.getElementById("headContent").innerHTML = itm;
        var link = document.getElementById('accountSection');
        link.style.display = 'none'; //or
        //link.style.visibility = 'hidden';
    }


</script>
and image.aspx code

HTML
<a href="#" önclick="return showhead('imagename','subcategoryname');"></a>




My VB Code In string builder

VB
Private Sub bindCategory()

    Dim dtCategory As DataTable
    Dim dtSubCategory As DataTable

    Dim strCategoryName As String
    Dim strCategoryImage As String
    Dim strCategoryId As Integer
    Dim strSubCategoryName As String
    Dim strSubCategoryId As Integer

    Dim sb = New StringBuilder

    dtCategory = GetCategory()
    For Each row As DataRow In dtCategory.Rows
        strCategoryName = row.Item("Category_Name").ToString
        strCategoryImage = row.Item("Category_ImageFilePath").ToString
        strCategoryId = row.Item("CategoryID")

        sb.Append("<li>")
        sb.Append("<div class="responsive-accordion-head"><img src=" + strCategoryImage + "></img>  <a önclick="return showhead(" fa="" fa-plus="" responsive-accordion-plus="" fa-fw="></i><i class=" fa-minus="" responsive-accordion-minus=""><div class="responsive-accordion-head">
        '        <span class="fa fa-automobile"></span>  <a önclick="return showhead('fa fa-automobile','section Three');">
        '            id="">section Three </a>^__i class="fa fa-minus responsive-accordion-minus fa-fw">
        '    </div>



        sb.Append("<div class="responsive-accordion-panel">")
        sb.Append("<div class="menu">")

        dtSubCategory = GetAllSubCategory(strCategoryId)

        For Each row1 As DataRow In dtSubCategory.Rows
            strSubCategoryName = "--" + row1.Item("SubCategory_Name").ToString
            'strSubCategoryId = row1.Item("CategoryID")
            strSubCategoryId = row1.Item("SubCategoryID")

            sb.Append("<ul>")
            'sb.Append("<li><a href="#" önclick="return showhead(">" + strSubCategoryName + "</a></li>")

            '<li><a href="#" önclick="return showhead('fa fa-automobile','Submenu1');">Submenu1</a></li>

            sb.Append("<li><a href="#" önclick="return showhead(" strcategoryimage="," strsubcategoryname=");">" + strSubCategoryName + "</a></li>")

            sb.Append("</ul>")
        Next
        sb.Append("</div>")
        sb.Append("</div>")
        sb.Append("</a></div></li>")
    Next
    ltrlCategory.Text = sb.ToString()


End Sub

but it's not working javascript call showhead().....

so, please help me.....
Posted
Updated 25-May-14 21:53pm
v4

1 solution

XML
Private Sub bindCategory()

    Dim dtCategory As DataTable
    Dim dtSubCategory As DataTable

    Dim strCategoryName As String
    Dim strCategoryImage As String
    Dim strCategoryId As Integer
    Dim strSubCategoryName As String
    Dim strSubCategoryId As Integer

    Dim sb = New StringBuilder

    dtCategory = GetCategory()
    For Each row As DataRow In dtCategory.Rows
        strCategoryName = row.Item("Category_Name").ToString
        strCategoryImage = row.Item("Category_ImageFilePath").ToString
        strCategoryId = row.Item("CategoryID")

        sb.Append("<li>")
        sb.Append("<div class='responsive-accordion-head'><img src=" + strCategoryImage + "></img>&nbsp;&nbsp;<a onclick='return showhead('" + strCategoryImage + "','" + strCategoryName + "');>" + strCategoryName + "</a> <i class='fa fa-plus responsive-accordion-plus fa-fw'></i><i class='fa fa-minus responsive-accordion-minus fa-fw'></i></div>")

        sb.Append("<div class='responsive-accordion-panel'>")
        sb.Append("<div class='menu'>")

        dtSubCategory = GetAllSubCategory(strCategoryId)

        For Each row1 As DataRow In dtSubCategory.Rows
            strSubCategoryName = "--" + row1.Item("SubCategory_Name").ToString
            'strSubCategoryId = row1.Item("CategoryID")
            strSubCategoryId = row1.Item("SubCategoryID")

            sb.Append("<ul>")
            'sb.Append("<li><a href='#' onclick='return showhead('" + strCategoryImage + "','" + strSubCategoryName + "');'>" + strSubCategoryName + "</a></li>")

            '<li><a href="#" onclick="return showhead('fa fa-automobile','Submenu1');">Submenu1</a></li>

            sb.Append("<li><a href='#' onclick=""return showhead('" + strCategoryImage + "','" + strSubCategoryName + "');"">" + strSubCategoryName + "</a></li>")

            'sb.Append("<li><a href='#' onclick=""return showhead(<img src='" + strCategoryImage + "' />','" + strSubCategoryName + "');"">" + strSubCategoryName + "</a></li>")

            sb.Append("</ul>")
        Next
        sb.Append("</div>")
        sb.Append("</div>")
        sb.Append("</li>")
    Next
    ltrlCategory.Text = sb.ToString()


End Sub
 
Share this answer
 
v2
Comments
phil.o 26-May-14 7:57am    
By concatenating strings like you do in the StringBuilder, you are completely defeating the purpose of the StringBuilder.
Better look at the StringBuilder.AppendFormat() method, which acts quite like the String.Format() method.
StringBuilder.AppendFormat()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900