Click here to Skip to main content
15,885,949 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Created Div Dynamically,with One Div Inside Another and want to hide the content div on click of the outer div .I created Id of the div Dynamically through webservice but in the jquery ajax the id is not getting and i am unable to hide the content div please give me some links or code or any other kind of suggestion

additional information copied from comment below
MyWebservice.asmx.vb

VB
<webmethod()> _
    Public Function ChkBoxService() As String
        Dim sql As String = "select distinct FoodType from HallFoodingTrans where HallCode= 'HC1309000004'"
        Dim con As New SqlConnection(ConfigurationManager.AppSettings("myConnection"))
        Dim cmd As New SqlCommand(sql, con)
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet()
        da.Fill(ds)
        'var(id = "id")
        Dim lbl As String = "lbl"
        Dim dividouter As String = "dividouter"
        Dim dividinner As String = "dividinner"
        Dim chkboxFoodName As String = "chkboxFoodName"
        Dim labelFoodRate As String = "labelFoodRate"
        Dim txtInputFoodRate As String = "txtInputFoodRate"


        Dim tablestring As String = ""
        If ds.Tables(0).Rows.Count <> 0 Then

            Dim i As Integer = 0

            For Each dr As DataRow In ds.Tables(0).Rows
                tablestring = tablestring + ("<div id='dividouter" & i & "'  >")
                tablestring = tablestring + "<label id='lbl" & i & "' >" & dr("FoodType").ToString() & "</label> "

                Dim sql1 As String = "select distinct FoodName,Rate from HallFoodingTrans where FoodType= '" & dr("FoodType").ToString() & "' and HallCode= 'HC1309000004 '"
                Dim con1 As New SqlConnection(ConfigurationManager.AppSettings("myConnection"))
                Dim cmd1 As New SqlCommand(sql1, con1)
                Dim da1 As New SqlDataAdapter(cmd1)
                Dim ds1 As New DataTable()
                da1.Fill(ds1)

                Dim j As Integer = 0
                If ds1.Rows.Count > 0 Then

                    tablestring = tablestring + ("<div id='dividinner" & i & "" & j & "' >")
                    tablestring = tablestring + "<table width='100%'><tr><td>First Column Head</td><td>Second column Head</td><td>Third column Heading</td></tr>"
                    Do While j < ds1.Rows.Count
                        With ds1.Rows(j)

                            tablestring = tablestring + "<tr><td><input type='checkbox' id='chkboxFoodName" & i & "" & j & "' >" & .Item("FoodName").ToString & "</td><td><label id='labelFoodRate" & i & "" & j & "' >" & .Item("Rate").ToString & "</td><td><input type='text' id='txtInputFoodRate" & i & "" & j & "'></td></tr>"

                            j = j + 1

                        End With
                    Loop

                    tablestring = tablestring + "</table>"
                    tablestring = tablestring + "</div>"

                End If

                tablestring = tablestring + "</div>"

                i += 1


            Next
        End If
        Return tablestring

    End Function

*************************
Default.aspx

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
<script src="js/jquery-1.9.1.js" type="text/javascript"></script>
 <script type="text/javascript">
    $(document).ready(function(){
  
    $.ajax({
      type: "POST",
      url: "MyWebService.asmx/ChkBoxService",  
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (data) {
    
        var myData = data.d;
        alert(myData);
        $('#chkwebservice').html(myData);
      }
    });
});

</script>
</head>
<body>
    <form id="form1"  runat="server">
    <div id="chkwebservice" style ="background-color:Green; height:500px;">
    
</div>

    </form>
</body>
</html>
Posted
Updated 4-Apr-14 23:47pm
v4
Comments
Er. Puneet Goel 3-Apr-14 8:02am    
Please provide the structure of you code (HTML). We will look into that for better solution.
SAYANTAN HOWLADAR 3-Apr-14 8:22am    
I Sent my Coding Structure ,Please Help me
SAYANTAN HOWLADAR 3-Apr-14 8:21am    
MyWebservice.asmx.vb

<webmethod()> _
Public Function ChkBoxService() As String
Dim sql As String = "select distinct FoodType from HallFoodingTrans where HallCode= 'HC1309000004'"
Dim con As New SqlConnection(ConfigurationManager.AppSettings("myConnection"))
Dim cmd As New SqlCommand(sql, con)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
'var(id = "id")
Dim lbl As String = "lbl"
Dim dividouter As String = "dividouter"
Dim dividinner As String = "dividinner"
Dim chkboxFoodName As String = "chkboxFoodName"
Dim labelFoodRate As String = "labelFoodRate"
Dim txtInputFoodRate As String = "txtInputFoodRate"



Dim tablestring As String = ""
If ds.Tables(0).Rows.Count <> 0 Then

Dim i As Integer = 0

For Each dr As DataRow In ds.Tables(0).Rows

tablestring = tablestring + ("<div id='dividouter" & i & "' >")
tablestring = tablestring + "<label id='lbl" & i & "' >" & dr("FoodType").ToString() & "</label> "



Dim sql1 As String = "select distinct FoodName,Rate from HallFoodingTrans where FoodType= '" & dr("FoodType").ToString() & "' and HallCode= 'HC1309000004 '"
Dim con1 As New SqlConnection(ConfigurationManager.AppSettings("myConnection"))
Dim cmd1 As New SqlCommand(sql1, con1)
Dim da1 As New SqlDataAdapter(cmd1)
Dim ds1 As New DataTable()
da1.Fill(ds1)





Dim j As Integer = 0
If ds1.Rows.Count > 0 Then

tablestring = tablestring + ("<div id='dividinner" & i & "" & j & "' >")
tablestring = tablestring + "<table width='100%'><tr><td>First Column Head</td><td>Second column Head</td><td>Third column Heading</td></tr>"
Do While j < ds1.Rows.Count
With ds1.Rows(j)


tablestring = tablestring + "<tr><td><input type='checkbox' id='chkboxFoodName" & i & "" & j & "' >" & .Item("FoodName").ToString & "</td><td><label id='labelFoodRate" & i & "" & j & "' >" & .Item("Rate").ToString & "</td><td><input type='text' id='txtInputFoodRate" & i & "" & j & "'></td></tr>"



j = j + 1



End With


Loop

tablestring = tablestring + "</table>"
tablestring = tablestring + "</div>"







End If



tablestring = tablestring + "</div>"

i += 1


Next
End If
Return tablestring

End Function
*************************
Default.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="js/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){


$.ajax({
type: "POST",
url: "MyWebService.asmx/ChkBoxService",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {

var myData = data.d;

alert(myData);
$('#chkwebservice').html(myData);


}
});




});

</script>
</head>
<body>
<form id="form1" runat="server">
<div id="chkwebservice" style ="background-color:Green; height:500px;">

</div>

</form>
</body>
</html>
thatraja 3-Apr-14 9:11am    
Post this details in your question(Yes, update your question using 'Improve question' link)

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