ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 17th, 2010, 10:24 AM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
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]

Reply With Quote
  #2  
Old December 21st, 2010, 02:07 PM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
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

Reply With Quote
  #3  
Old December 27th, 2010, 09:08 AM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
Can anyone know about this.
Give some clue..

Thanks

Reply With Quote
  #4  
Old December 28th, 2010, 12:59 AM
Doug G Doug G is online now
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
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
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

Reply With Quote
  #5  
Old December 28th, 2010, 08:08 AM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
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="">

Reply With Quote
  #6  
Old December 28th, 2010, 09:44 PM
Doug G Doug G is online now
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
Review the remarks here and verify you are able to use recordcount in your code http://msdn.microsoft.com/en-us/lib...v=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?

Reply With Quote
  #7  
Old December 29th, 2010, 07:26 AM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
@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.

Reply With Quote
  #8  
Old December 29th, 2010, 04:42 PM
Doug G Doug G is online now
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
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.

Reply With Quote
  #9  
Old January 5th, 2011, 11:21 AM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
@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..

Reply With Quote
  #10  
Old January 5th, 2011, 03:37 PM
Doug G Doug G is online now
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
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.

Reply With Quote
  #11  
Old January 5th, 2011, 05:30 PM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
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


			%>

Reply With Quote
  #12  
Old January 5th, 2011, 08:58 PM
Doug G Doug G is online now
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
Quote:
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.

Reply With Quote
  #13  
Old January 5th, 2011, 10:34 PM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
@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.

Reply With Quote
  #14  
Old January 6th, 2011, 02:36 AM
Doug G Doug G is online now
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
Quote:
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Dynamically add checkbox to form

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap