Paging and saving the values of checkboxes
I'm using paging which uses a stored procedure to filter by letter. I need to save the values of checkboxes as I submit the form as I filter by letter. I have had a previous question similar to this which worked great but I want to be able to keep my stored procedure.
Stored procedure:
ALTER PROCEDURE [dbo].[A_Page_Paging]
@selected_Char char(1) = null,
@permissionID int = null
as
if @permissionID = ''
if @selected_Char = '#'
select * from A_Page where P_Description like '[^a-z]%'
else if @selected_Char = '!'
select * from A_Page
order by P_Description
else
select * from A_Page where P_Description like @selected_Char + '%'
else
select P_PageID, P_Name, P_Description from A_Permission
inner join L_PagePermission
on P_PermissionID = PP_PermissionID
inner join A_Page
on P_PageID = PP_PageID
where P_PermissionID = @permissionID
order by P_Name
Paging buttons:
<input id="buttonStyle" type="submit" name="Paging_Button" value="#">
<% for i = 97 to 122 %>
<input id="buttonStyle" type="submit" name="Paging_Button" value="<%=CHR(i) %>">
<% next %>
<input id="buttonStyle" type="submit" name="Paging_Button" value="All">
Function to save checkboxes and checkbox (the function will only work for example if I select a checkbox with the value starting with A then filter by A the checkbox will show, if I filter by B it wont):
'Checkbox check
Function CheckedByUser(id)
Dim x
CheckedByUser = "checked=""checked"""
For x=1 To Request.Form("selectedRecord").Count
If Trim(Request.Form("selectedRecord").Item(x)) = Trim(id) Then
Exit Function
End If
Next
CheckedByUser = ""
End Function
<input type="checkbox" name="selectedRecord" value="<%=开发者_如何学运维objRS("P_PageID")%>" <%=CheckedByUser(objRS("P_PageID")) %>>
Previous answer to fix paging problem but requires me to change my stored procedure which i prefer not to do:
<%
Do Until objRS.EOF
Response.Write("<input type=""checkbox"" name=""selectedRecord"" value=""" & objRS("Id") & """ " & WasCheckedByUser(objRS("Id")))
If Len(Request.Form("Page"))=1 And Trim(Left(objRS("Id"), 1))<>Trim(Request.Form("Page")) Then
Response.Write(" style=""display: none;""")
End If
Response.Write(" />")
objRS.MoveNext
Loop
%>
Executing stored procedure
connectionstring = obj_ADO.getconnectionstring
Set objCon = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
set objComm = CreateObject("ADODB.Command")
objCon.Open connectionstring
objComm.ActiveConnection = objCon.ConnectionString
objComm.CommandText = "A_Page_Paging"
objComm.CommandType = 4
Set objParameter = objComm.CreateParameter
objParameter.Name = "selected_Char"
objParameter.Type = 129
objParameter.Direction = 1
objParameter.Size = 3
objParameter.Value = Selected_Button
objComm.Parameters.Append objParameter
Set objParameter2 = objComm.CreateParameter
objParameter2.Name = "PermissionID"
objParameter2.Type = 129
objParameter2.Direction = 1
objParameter2 .Size = 3
objParameter2 .Value = P_ID
objComm.Parameters.Append objParameter2
set objRS = objComm.Execute
Change this line in your code:
objParameter.Value = Selected_Button
To this instead:
objParameter.Value = "!"
The code you already have in the loop should hide the checkboxes that are not part of the current "page".
精彩评论