#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4

    Dynamically add checkbox to form


    I am displaying table data on my form. I am getting data from sql server.
    Now i want to add checkbox to my table(asp form). and at the same time i want to add new column to sqltable also.
    If that row is checked and i am saving it to sqltable.

    I am kinda confused here. is it possible to do..
    Can any one help me here..

    I have already displaying the sql table on the form.(but not check boxes).

    So can any one help me here how to add checkbox dynamically to form.
    and a new column in sql table(with yes/no checkbox)..

    if u didn't understand my question i will tell you again..



    Plz help me here to getout of this problem,..



    [asp/vbscript/javascript/sqlserver]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    I have dynamically added the checkbox to my form.. pagination and checkbox checked is not working.
    Can any one have clue where i went wrong.


    Pagination displaying all the rows in each page. It should have display 12 rows per page . But it is displaying the all rowns in each page click..


    This the code i have used.

    Code:
    <% 
    					
    	OpenSQLConn
    	iPageSize = 12
    	If Request.QueryString("page") = "" Then
    	iPageCurrent = 1
    	Else
    	iPageCurrent = CInt(Request.QueryString("page"))
    	End If
    	strSQL = "SELECT * from products"
    	Set rs = Server.CreateObject("ADODB.Recordset")
    	rs.PageSize = iPageSize
    	rs.CacheSize = iPageSize
    	rs.Open strSQL, Conn, adOpenStatic, adLockReadOnly, adCmdText
    	iPageCount = rs.PageCount
    	iFieldCount = rs.Fields.Count
    	iRecordCount = rs.RecordCount
    		
    	while not rs.EOF  'checkbox declaration starts from here	
                 dim tot1,totval
    	totval=int(rs.RecordCount)
    	tot1=0	
       %>
    
    <tr><td><input type="checkbox" name="cb&<%= k %>" value="<%=rs("sno") %>"></td>
            <td> <% =rs("Prodid")%> </td>
            <td> <% =rs("prod_name")%> </td></tr>
    
    <%
     k=k+1
    rs.MoveNext
    wend
    %> 
    
    
    
      <%
    	Dim iPageSize
    	Dim iPageCount
    	Dim iPageCurrent
    	Dim strOrderBy
    	Dim iRecordsShown
    	Dim iFieldCount
    	Dim iRecordCount
    	Dim LoopRecordCount
    	Dim pageNum
    	Dim counter
    	Dim markShowPage
    	Dim I, J,k
    	k=1
    					
    	If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
    	If iPageCurrent < 1 Then iPageCurrent = 1
    	If iPageCount = 0 Then
    	Response.Write "No records found!"
    	Else
    	rs.AbsolutePage = iPageCurrent
    	Dim arrDBData
    	ReDim arrDBData(iFieldCount, iRecordCount)
    	LoopRecordCount = 0
    		
    	Do While LoopRecordCount < iPageSize And Not rs.EOF
    	For I = 0 To rs.Fields.Count - 1
    	arrDBData(I, LoopRecordCount) = rs.Fields(I)
    	Next
    	LoopRecordCount = LoopRecordCount + 1
    	rs.MoveNext
    	Loop
    	End If
    	iRecordCount = iRecordCount - 1
    	iFieldCount  = iFieldCount - 1
    	LoopRecordCount = LoopRecordCount - 1
    	pageNum = Round(iRecordCount/iPageSize)
    	If pageNum < (iRecordCount/iPageSize) Then   pageNum = pageNum + 1
    	Response.Write "&nbsp;&nbsp;<b>Page: "
    	For counter = 1 To pageNum  
    	if counter=iPageCurrent then
    	Response.Write "&nbsp;<span class=activepage>&nbsp;"
    	Response.Write counter
    	Response.Write "&nbsp;</span>"
    	markShowPage=1
    	else
    	Response.Write "&nbsp;<a onclick=exitoff() href=ma1.asp?page="
    	Response.Write counter
    	Response.Write " class=listingLink>"
    	Response.Write counter
    	Response.Write "</a>"
    	end if
    	Next
    	Response.Write "</b>"
    	Response.Write "&nbsp;&nbsp;"
    	Response.Write "<b>"
    	Response.Write "<a href=ma1.asp?page="
    	If iPageCurrent = 1 Then
    	Response.Write pageNum
    	else
    	Response.Write iPageCurrent-1
    	end if
    	Response.Write " class=listingLink>Back</a>&nbsp;&nbsp;"
    	Response.Write "<a href=ma1.asp?page="
    	If iPageCurrent = pageNum Then
    	Response.Write "1"
    	else
    	Response.Write iPageCurrent+1
    	end if
    	Response.Write " class=listingLink>Next</a>"
    	Response.Write "</b>"
    	rs.close
    	Conn.Close
    	%>
    Thanks in advance
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    Can anyone know about this.
    Give some clue..

    Thanks
  6. #4
  7. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    What is the question now? What debug steps have you taken with what debug results? Have you inserted any response.write debug probes to verify variable contents in your code.

    Using the recordset.rrecordcount property is often a poor choice, recordcount may not be populated properly.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4

    Question


    Other than record Count what i need to use...
    I am not good in pagination though..
    I have added a dynamic check box to my table(which i am displaying on the form).But it is not displaying the checked values.

    I have entered checked values to sql table through insert command.

    <input type="checkbox" name="ch" value="">
  10. #6
  11. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    Review the remarks here and verify you are able to use recordcount in your code http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    You can probably find sample pagination code by searching these forums or sites like www.w3schools.com.

    Again, what is the question now?
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    @Doug
    Thanks for giving good information.. I learned something..

    Ok i will use adApproxPosition and adBookmark.


    My another question is
    I am displying dynamic checkbox for each row in a table.(i am displaying data in a table format from sqldatabase).

    I have changed two(rows) checkboxes value in sql table. But it is not showing on the form.

    Sql table
    ------------------------
    Sno bit
    id int
    name char(6)How can i display checked checkbox data on form.
  14. #8
  15. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    Review the flow of your code. If you're adding a checkbox in the browser code it won't have access to any updated information from the web server, they are two different computers running two different programs with no direct connection between the two.

    You could investigate using ajax to perform a query on the server and update the html in the browser without reposting the entire page.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    @Doug

    yes. I am adding check box on the form that's why it's not displaying check box value.. Is there a way to display check box and value(value from SQL DB).

    At line no 151
    I have declared dynamic check box on the browser.
    Code:
    <input type="check box"  name="ch" value="<%= rs("Sno") =%>">
    If I declare like this I am getting an error like this
    Microsoft vb script run time
    type mismatch "rs" at line no 151


    I am not good in asp.. I don't have much idea about ajax.. can give me some help here..
  18. #10
  19. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    Your code won't work. the web server will have no knowledge of rs("Sno") at the time you create the checkbox. You'll have to use some ajax query to get server data, or repost the page and let the server create the checkbox rather than your client javascript.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    I really don't have knowledge on ajax and you said let the server create the check box..How server will create check box?
    I am looking for this kind of information from morning. I didn't get it

    this is the code i am using...
    Code:
    <%
    				OpenSQLConn
    				Dim iPageSize
    				Dim iPageCount
    				Dim iPageCurrent
    				Dim strOrderBy
    				Dim iRecordsShown
    				Dim iFieldCount
    				Dim iRecordCount
    				Dim LoopRecordCount
    				Dim pageNum
    				Dim counter
    				Dim markShowPage
    				Dim I, J
    					iPageSize = 15
    				If Request.QueryString("page") = "" Then
    					iPageCurrent = 1
    				Else
    					iPageCurrent = CInt(Request.QueryString("page"))
    				End If
    
    				strSQL = "SELECT * from products"
    
    				Set rs = Server.CreateObject("ADODB.Recordset")
    
    					rs.PageSize = iPageSize
    					rs.CacheSize = iPageSize
    					rs.Open strSQL, Conn, adOpenStatic, adLockReadOnly, adCmdText
    
    					iPageCount = rs.PageCount
    					iFieldCount = rs.Fields.Count
    					iRecordCount = rs.RecordCount
    
    					If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
    					If iPageCurrent < 1 Then iPageCurrent = 1
    
    					If iPageCount = 0 Then
    					Response.Write "No records found!"
    					Else
    					rs.AbsolutePage = iPageCurrent
    
    					Dim arrDBData
    					ReDim arrDBData(iFieldCount, iRecordCount)
    						LoopRecordCount = 0
    
    						'arrDBData = rs.GetRows()
    
    						Do While LoopRecordCount < iPageSize And Not rs.EOF
    							For I = 0 To rs.Fields.Count - 1
    								arrDBData(I, LoopRecordCount) = rs.Fields(I)
    							Next
    								LoopRecordCount = LoopRecordCount + 1
    								rs.MoveNext
    						Loop
    
    						rs.Close
    					Set rs = Nothing
    					Conn.Close
    					
    					End If
    
    					iRecordCount = iRecordCount - 1
    					iFieldCount  = iFieldCount - 1
    					LoopRecordCount = LoopRecordCount - 1
    
    					pageNum = Round(iRecordCount/iPageSize)
    					If pageNum < (iRecordCount/iPageSize) Then pageNum = pageNum + 1
    
    					Response.Write "&nbsp;&nbsp;<b>Page: "
    					For counter = 1 To pageNum  
    	if counter=iPageCurrent then
    		Response.Write "&nbsp;<span class=activepage>&nbsp;"
    		Response.Write counter
    		Response.Write "&nbsp;</span>"
    		markShowPage=1
    	else
    		Response.Write "&nbsp;<a onclick=exitoff() href=products.asp?page="
    		Response.Write counter
    		Response.Write " class=listingLink>"
    		Response.Write counter
    		Response.Write "</a>"
    	end if
    Next
    Response.Write "</b>"
    
    Response.Write "&nbsp;&nbsp;"
    
    Response.Write "<b>"
    
    Response.Write "<a href=products.asp?page="
    If iPageCurrent = 1 Then
    	Response.Write pageNum
    else
    	Response.Write iPageCurrent-1
    end if
    Response.Write " class=listingLink>Back</a>&nbsp;&nbsp;"
    Response.Write "<a href=products.asp?page="
    If iPageCurrent = pageNum Then
    	Response.Write "1"
    else
    	Response.Write iPageCurrent+1
    end if
    Response.Write " class=listingLink>Next</a>"
    
    Response.Write "</b>"
    
    				For I = 0 To LoopRecordCount
    				Response.Write "<tr>" & vbCrLf
    				Response.write "<td>" 
    				%>
    				<input type="checkbox" name="ch" value="" >
                    <%
    				Response.write"</td>"
    				For J = 0 To ifieldCount
    				Response.Write vbTab & "<td>" & arrDBData(J, I) & "</td>" & vbCrLf
    				Next ' J
    				Response.Write "</tr>" & vbCrLf
    				Next ' I
    
    'Const adOpenStatic   = 3
    'Const adLockReadOnly = 1
    'Const adCmdText      = &H0001
    
    
    			%>
  22. #12
  23. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    I really don't have knowledge on ajax
    Is your google key borked? I'm unable to give you any more suggestions that what I've already given. There is plenty of ajax information you can study.

    As far as the big lump of code you just provided, response.write the checkbox html instead of breaking out of asp like
    Code:
    response.write "<input type=""checkbox"" name=""ch"" value="""" >"
    You can then change the name and/or value your code gives each checkbox as you go through each record.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    39
    Rep Power
    4
    @doug
    I am using Google only.. but i am trying different ways to get correct output... so I am totally confused..



    Million thanks to you..
    whenever I post my query u are the one giving answers and advising right direction to me..

    this is my first project doing this by myself. so getting frustration whether i am doing correct way or not.. even if i get correct answers i will post queries to make sure.
  26. #14
  27. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    this is my first project doing this by myself.
    Perhaps you should practice with some simple asp projects before getting in to database generated dynamic html objects.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo