The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ASP Programming
|
Dynamically add checkbox to form
Discuss Dynamically add checkbox to form in the ASP Programming forum on Dev Shed. Dynamically add checkbox to form ASP Programming forum discussing Active Server Pages coding techniques and problem solving methods. Use VBScript or Jscript to make dynamic web applications.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 17th, 2010, 10:24 AM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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]
|

December 21st, 2010, 02:07 PM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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 " <b>Page: "
For counter = 1 To pageNum
if counter=iPageCurrent then
Response.Write " <span class=activepage> "
Response.Write counter
Response.Write " </span>"
markShowPage=1
else
Response.Write " <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 " "
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> "
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
|

December 27th, 2010, 09:08 AM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
|
|
|
Can anyone know about this.
Give some clue..
Thanks
|

December 28th, 2010, 12:59 AM
|
|
|
|
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
|

December 28th, 2010, 08:08 AM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
|
|
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="">
|

December 28th, 2010, 09:44 PM
|
|
|
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?
|

December 29th, 2010, 07:26 AM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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.
|

December 29th, 2010, 04:42 PM
|
|
|
|
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.
|

January 5th, 2011, 11:21 AM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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..

|

January 5th, 2011, 03:37 PM
|
|
|
|
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.
|

January 5th, 2011, 05:30 PM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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 " <b>Page: "
For counter = 1 To pageNum
if counter=iPageCurrent then
Response.Write " <span class=activepage> "
Response.Write counter
Response.Write " </span>"
markShowPage=1
else
Response.Write " <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 " "
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> "
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
%>
|

January 5th, 2011, 08:58 PM
|
|
|
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.
|

January 5th, 2011, 10:34 PM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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.
|

January 6th, 2011, 02:36 AM
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|