none
Request.QueryString的問題 RRS feed

  • 一般討論

  • 我想把sql的[PrimaryClass]= 1 條件
    做成必須根據前一頁的a.aspx來判斷所要帶入的值
    (b.aspx [PrimaryClass]=@PrimaryClass是根據a.aspx ImageButton1的而來)
    請問我要怎麼改? 弄很久都無法用出來

    a.aspx
                                        <asp:DataList ID="DataList2" runat="server" DataKeyField="PrimaryClass" DataSourceID="SqlDataSource1">
                                            <ItemTemplate>
                                                <table style="width: 291px">
                                                    <tr>
                                                        <td colspan="2">
                                                <asp:Label ID="Label4" runat="server" Font-Size="Small" Text="更新日期:"></asp:Label>
                                                <asp:Label ID="IssueDateLabel" runat="server" Font-Size="Small" Text='<%# Eval("IssueDate","{0:yyyy/MM/dd}") %>'></asp:Label></td>
                                                        <td style="width: 100px; text-align: right">
                                                <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/more.bmp" PostBackUrl='<%# Eval("PrimaryClass", "Information.aspx?pc={0}") %>'/></td>
                                                    </tr>
                                                </table>
                                            </ItemTemplate>
                                        </asp:DataList>
    b.aspx.vb
    Imports System
    Imports System.Configuration
    Imports System.Data
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.HtmlControls
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Data.SqlClient
    
    Partial Class _Information
        Inherits System.Web.UI.Page
    
        Private Page_Size As Integer = 1
        Private Page_Count As Integer = 0 
        Private Page_Index As Integer
        Private conn As SqlConnection
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            ItemDatabound()
        End Sub
        Private Function GetDataSource() As PagedDataSource
            conn = New SqlConnection("server=140.131.114.241; database=Coupon; uid=123; pwd=123;")
            Dim da As New SqlDataAdapter("SELECT * FROM [Sales] WHERE ([PrimaryClass]= 1) ORDER BY [IssueDate] DESC", conn)
            conn.Open()
            Dim ds As New DataSet()
            da.Fill(ds, "Tb")
            Try
                Page_Index = Convert.ToInt32(Request("Pid"))
            Catch
                Page_Index = 1
            End Try
            If Page_Index = 0 Then
                Page_Index = 1
            End If
            Dim pds As New PagedDataSource()
            pds.AllowPaging = True
            pds.PageSize = Page_Size
            pds.CurrentPageIndex = Page_Index - 1
            pds.DataSource = ds.Tables(0).DefaultView
    
            Dim TolPage As Integer
            TolPage = pds.PageCount
            Dim CurPage As Integer
            If (Request.QueryString("Pid") <> Nothing) Then
                CurPage = CInt(Request.QueryString("Pid"))
            Else
                CurPage = 1
            End If
            'lblCurPage.Text = "目前在第 " + CurPage.ToString() + " 頁,共 " + TolPage.ToString() + " 頁"
            lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Pid=1"
            lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Pid=" + TolPage.ToString()
            If (Not pds.IsFirstPage) Then
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Pid=" + Convert.ToString(CurPage - 1)
            Else
                lnkPrev.Visible = False
                lnkFirst.Visible = False
            End If
    
            If (Not pds.IsLastPage) Then
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Pid=" + Convert.ToString(CurPage + 1)
            Else
                lnkNext.Visible = False
                lnkLast.Visible = False
            End If
            Return pds
        End Function
        Private Sub ItemDatabound()
            AddHandler DlUser.ItemDataBound, AddressOf DlUser_ItemDataBound
            '生成綁定事件 
            DlUser.DataSource = GetDataSource()
            DlUser.DataBind()
            conn.Close()
        End Sub
    
        Protected Sub DlUser_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
            Page_Count = GetDataSource().PageCount
    
            WebFunction()
        End Sub
        ''' <summary> 
        ''' 分頁 
        ''' </summary> 
        Private Sub WebFunction()
            '分頁 
            '這個頁面只是顯示為了123456這樣頁面.如果要顯示123456789,要重新做考慮下面算法 
            Dim StbTb As String = " "
            Dim StrLink As String = Nothing
            If Page_Count <= 5 Then
                For j As Integer = 1 To Page_Count
                    If j = Page_Index Then
                        StrLink += ("<font color=#ff6699>" & j.ToString() & "</font>") + StbTb
                    Else
                        StrLink += (("<a href=?Pid=" & j & ">") + j.ToString() & "</a>") + StbTb
                    End If
                Next
            Else
                If Page_Index > 2 Then
                    If (Page_Count - Page_Index) >= 5 OrElse Page_Index <= 5 Then
                        For j As Integer = Page_Index - 2 To Page_Index + 2
                            If j = Page_Index Then
                                StrLink += ("<font color=#ff6699>" & j.ToString() & "</font>") + StbTb
                            Else
                                StrLink += (("<a href=?Pid=" & j & ">") + j.ToString() & "</a>") + StbTb
                            End If
    
                        Next
                    Else
                        For j As Integer = Page_Count - 4 To Page_Count
                            If j = Page_Index Then
                                StrLink = ((StrLink & "<font color=#ff6699>") + j.ToString() & "</font>") + StbTb
                            Else
                                StrLink += (("<a href=?Pid=" & j & ">") + j.ToString() & "</a>") + StbTb
                            End If
                            If j >= Page_Count Then
                                Exit For
                            End If
                        Next
                    End If
                Else
                    For j As Integer = 1 To 5
                        If j = Page_Index Then
                            StrLink += ("<font color=#ff6699>" & j.ToString() & "</font>") + StbTb
                        Else
                            StrLink += (("<a href=?Pid=" & j & ">") + j.ToString() & "</a>") + StbTb
                        End If
                    Next
                End If
            End If
            Dim strToal As String = ("目前" & Page_Index.ToString()) + StbTb
            strToal += ("總共" & Page_Count.ToString() & "|") + StbTb + StbTb
            LyLink.Text = strToal + StrLink
        End Sub
    End Class
    
    
    
    • 已移動 小朱MVP, Moderator 2009年8月31日 上午 08:50 (從:Visual Basic)
    • 已變更類型 Lolota Lee 2009年9月7日 上午 02:01 發問者未繼續回覆測試結果
    • 已變更類型 Lolota Lee 2009年9月9日 上午 12:58 發問者未繼續回覆
    2009年8月31日 上午 08:14

所有回覆

  • 没看明白你要问什么

    Dim pc as String = Request.QueryString("pc")
     Dim da As New SqlDataAdapter("SELECT * FROM [Sales] WHERE ([PrimaryClass]= " + pc  + ") ORDER BY [IssueDate] DESC", conn)
    另外,在你的分页里面,需要加上pc
    比如

    Dim url As String = Request.CurrentExecutionFilePath
    url = url + "?pc=" + pc
    lnkNext.NavigateUrl = url  + "&Pid=" + Convert.ToString(CurPage + 1)
    • 已編輯 孟宪会 2009年8月31日 下午 12:52
    2009年8月31日 下午 12:45
  • 首先,跟您確認一下,您從a.aspx傳過去的url有無包含querystring?



    您可以這樣改試看看:
     <asp:ImageButton ID="ImageButton1" runat="server"
                    PostBackUrl='<%# "Information.aspx?pc=" + Eval("PrimaryClass") %>' />


    然後b網頁用, Request.QueryString["pc"]來接.



    年度軟體技術盛會微軟Tech.Days 9月22日全新登場, 您還在等什麼? 快報名就對了.


    2009年9月1日 上午 01:49
  • Hi,

    您的問題解決了嗎 ?


    Best Regards,
    Lolota

    年度軟體技術盛會微軟Tech.Days 9月22日全新登場, 您還在等什麼? 快報名就對了.


    2009年9月4日 上午 06:29
  • 嗯...........看起來是參數名不一致的關係

    你在a.aspx當中用
    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/more.bmp"
      PostBackUrl='<%# Eval("PrimaryClass", "Information.aspx?pc={0}") %>'/>

    所以QueryString只會有pc這個參數

    我想b.aspx應該用
    Page_Index = Convert.ToInt32(Request("pc")) 去接
    2009年9月5日 上午 04:10
    版主