如何通过会话将参数从page1.aspx传递到page2.aspx?

时间:2011-06-08 14:31:28

标签: asp.net vb.net session parameters

我有两个aspx页面。我需要将一个textbox(record_id)值作为参数从page1.aspx发送到page2.aspx,以便在VB代码隐藏页面的SqlCommand查询中使用。我想使用会话传递此参数。 Page1是一个gridview,它显示来自sql数据源的记录,并在编辑按钮上单击,用户被重定向到page2,它填充了几个文本框并下拉列表,并允许用户编辑记录。 page1.aspx这个:

<div id="header">
    <h1>Page1</h1>
</div>
<%-- <form id="form1" runat="server" style="text-align:left" > --%>
<div id="GridViewContainer" class="GridViewContainer" 
            style="width:4500px;height:700px;" >
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CssClass="GridView"  
    DataKeyNames="record_id" DataSourceID="SqlDataSource1" AllowPaging="true" PageSize="15">
    <PagerStyle   
            Font-Bold="true"     
            BackColor="#D6E7FF"  
            ForeColor="Blue"
             /> 
    <%-- <HeaderStyle CssClass="FrozenHeader" /> --%>
    <Columns>
        <%--<asp:CommandField ShowEditButton="True" OnClientClick="InquiryUpdate.aspx">
             <ControlStyle ForeColor="blue" />
        </asp:CommandField> --%>
        <asp:TemplateField HeaderText="Edit">  
                <ItemTemplate>
                    <asp:Button   
                        ID="ButtonEdit"  
                        runat="server"  
                        Text="Edit"
                        onclick="ButtonEdit"
                        PostBackUrl="Page2.aspx"
                        CommandName="edit"
                        CommandArgument='<%#Eval("record_id") %>'                           
                        OnClientClick="return confirm('Are you sure you want to edit this record?')"  
                        Height="20"  
                        ForeColor="Navy"  
                        Font-Bold="true"  
                        />  
                </ItemTemplate>  
            </asp:TemplateField>
        <asp:BoundField DataField="record_id" HeaderText="Record Id" itemstyle-width="20px"
            InsertVisible="False" ReadOnly="True" SortExpression="record_id" />
        <asp:BoundField DataField="location" HeaderText="Location" itemstyle-width="150px"
            InsertVisible="False" ReadOnly="True" SortExpression="location" />
        <asp:BoundField DataField="ref_date" HeaderText="Referral Date" itemstyle-width="40px"
            SortExpression="ref_date" ReadOnly="True" />
        <%-- <asp:TemplateField SortExpression="ref_date" HeaderText="Referral Date">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList11" Runat="server" 
                  DataSourceID="SqlDataSource12"
                    DataTextField="ref_date" DataValueField="ref_date" 
                    SelectedValue='<%# Bind("ref_date") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("ref_date") %>' 
                  ID="Label2"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField> --%>
        <asp:BoundField DataField="pot_res" HeaderText="Potential Resident" itemstyle-width="200px"
            SortExpression="pot_res" />
        <asp:TemplateField SortExpression="app_admit" HeaderText="Approval for Admit" itemstyle-width="50px">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList4" Runat="server" 
                  DataSourceID="SqlDataSource5"
                    DataTextField="app_admit" DataValueField="app_admit" 
                    SelectedValue='<%# Bind("app_admit") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("app_admit") %>' 
                  ID="Label3"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="reason_not_admit" HeaderText="Reason Not Admitting" itemstyle-width="200px"
            SortExpression="reason_not_admit" />
        <asp:TemplateField SortExpression="app_by" HeaderText="Denial Approved By" itemstyle-width="200px">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList40" Runat="server" 
                  DataSourceID="SqlDataSource40"
                    DataTextField="app_by" DataValueField="app_by" 
                    SelectedValue='<%# Bind("app_by") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("app_by") %>' 
                  ID="Label40"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="zip_code" HeaderText="Zip Code" itemstyle-width="30px"
            SortExpression="zip_code" />
        <asp:TemplateField SortExpression="assess" HeaderText="Assess" itemstyle-width="70px">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList5" Runat="server" 
                  DataSourceID="SqlDataSource6"
                    DataTextField="assess" DataValueField="assess" 
                    SelectedValue='<%# Bind("assess") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("assess") %>' 
                  ID="Label4"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField SortExpression="tour" HeaderText="Tour" itemstyle-width="50px">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList6" Runat="server" 
                  DataSourceID="SqlDataSource7"
                    DataTextField="tour" DataValueField="tour" 
                    SelectedValue='<%# Bind("tour") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("tour") %>' 
                  ID="Label5"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="hear_us" HeaderText="How did your hear about us?" 
            SortExpression="hear_us" itemstyle-width="100px" />
        <asp:BoundField DataField="name_case_mngr" HeaderText="Name/Case Manager" itemstyle-width="100px"
            SortExpression="name_case_mngr" />
        <asp:TemplateField SortExpression="hos_org" HeaderText="Hospital/Organization" itemstyle-width="150px">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList7" Runat="server" 
                  DataSourceID="SqlDataSource8"
                    DataTextField="hos_org" DataValueField="hos_org" 
                    SelectedValue='<%# Bind("hos_org") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("hos_org") %>' 
                  ID="Label6"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="doctor" HeaderText="Doctor" itemstyle-width="150px"
            SortExpression="doctor" />
        <asp:BoundField DataField="pat_diag" HeaderText="Patient Diagnosis" itemstyle-width="150px"
            SortExpression="pat_diag" />
        <asp:TemplateField SortExpression="payor_key" HeaderText="Payor(key)" itemstyle-width="50px">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList8" Runat="server" 
                  DataSourceID="SqlDataSource9"
                    DataTextField="payor_key" DataValueField="payor_key" 
                    SelectedValue='<%# Bind("payor_key") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("payor_key") %>' 
                  ID="Label7"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="payor_detail" HeaderText="Payor Detail" itemstyle-width="150px"
            SortExpression="payor_detail" />
        <asp:TemplateField SortExpression="product_key" HeaderText="Product(Key)" itemstyle-width="150px">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList2" Runat="server" 
                  DataSourceID="SqlDataSource3"
                    DataTextField="product_key" DataValueField="product_key" 
                    SelectedValue='<%# Bind("product_key") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("product_key") %>' 
                  ID="Label8"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField SortExpression="decision_key" HeaderText="Decision(Key)" itemstyle-width="150px">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList9" Runat="server" 
                  DataSourceID="SqlDataSource10"
                    DataTextField="decision_key" DataValueField="decision_key" 
                    SelectedValue='<%# Bind("decision_key") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("decision_key") %>' 
                  ID="Label9"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField SortExpression="reason_key" HeaderText="reason(Key)" itemstyle-width="150px">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList10" Runat="server" 
                  DataSourceID="SqlDataSource11"
                    DataTextField="reason_key" DataValueField="reason_key" 
                    SelectedValue='<%# Bind("reason_key") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("reason_key") %>' 
                  ID="Label10"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="last_FU_date" HeaderText="Last F/U Date" itemstyle-width="40px"
            SortExpression="last_FU_date" />
        <%-- <asp:TemplateField SortExpression="last_FU_date" HeaderText="Last F/U Date">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList12" Runat="server" 
                  DataSourceID="SqlDataSource13"
                    DataTextField="last_FU_date" DataValueField="last_FU_date" 
                    SelectedValue='<%# Bind("last_FU_date") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("last_FU_date") %>' 
                  ID="Label11"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField> --%>
        <asp:BoundField DataField="pri_contact" HeaderText="Primary Contact" itemstyle-width="150px"
            SortExpression="pri_contact" />
        <asp:BoundField DataField="relationship" HeaderText="Relationship to Resident" itemstyle-width="150px"
            SortExpression="relationship" />
        <asp:BoundField DataField="street" HeaderText="Street" itemstyle-width="150px"
            SortExpression="street" />
        <asp:BoundField DataField="city" HeaderText="City" SortExpression="city" itemstyle-width="100px"/>
        <asp:TemplateField SortExpression="state" HeaderText="State">
           <EditItemTemplate>
                <asp:DropDownList ID="DropDownList3" Runat="server" 
                  DataSourceID="SqlDataSource4"
                    DataTextField="state" DataValueField="state" 
                    SelectedValue='<%# Bind("state") %>'>
                </asp:DropDownList>        
           </EditItemTemplate>
           <ItemTemplate>
               <asp:Label Runat="server" Text='<%# Bind("state") %>' 
                  ID="Label12"></asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="zip" HeaderText="Zip" SortExpression="zip" itemstyle-width="40px"/>
        <asp:BoundField DataField="phone" HeaderText="Phone" SortExpression="phone" itemstyle-width="110px"/>

        <asp:BoundField DataField="comments" 
            HeaderText="Comments" 
            SortExpression="comments" 
            itemstyle-width="250px"/>

        <asp:BoundField DataField="edited_date" HeaderText="Date Edited" itemstyle-width="100px"
            InsertVisible="False" ReadOnly="True" SortExpression="edited_date" />
        <asp:CommandField ShowEditButton="True" >
            <ControlStyle ForeColor="blue" />
        </asp:CommandField>
    </Columns>
    <HeaderStyle BackColor="#d6e7ff" ForeColor="black" />
</asp:GridView>
</div>

和page2.aspx.vb:

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Partial Public Class InquiryUpdate
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If HttpContext.Current.User IsNot Nothing Then
                Me.SqlDataSource6.SelectParameters.Clear()
                Me.SqlDataSource6.SelectParameters.Add("UserName", System.Data.DbType.[String], HttpContext.Current.User.Identity.Name)
            End If
        End If

        Dim dv As Data.DataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), Data.DataView)
        Dim conString As String = ConfigurationManager.ConnectionStrings("InquiryConnectionString").ToString()
        Dim sqlConn As New SqlConnection(conString)
        sqlConn.Open()
        Dim cmd As New SqlCommand("SELECT record_id, location, CONVERT(nvarchar(30),ref_date,110) as ref_date, pot_res, app_admit, reason_not_admit, app_by, zip_code, assess, tour, hear_us, name_case_mngr, hos_org, doctor, pat_diag, payor_key, payor_detail, product_key, decision_key, reason_key, CONVERT(nvarchar(30),last_FU_date,110) as last_FU_date, pri_contact, relationship, street,city, state, zip, phone, comments FROM temp_inquiry_table_denial where record_id='520'", sqlConn)
        cmd.Parameters.Add("@record_id", SqlDbType.Int).Value = DirectCast(Session("record_id"), Integer)
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable()
        da.Fill(dt)
        If dt.Rows.Count > 0 Then
            DisplayControls(True)
            txtLocation.Text = dt.Rows(0)("location").ToString()
            txtRefDate.Text = dt.Rows(0)("ref_date").ToString()
            pot_res.Text = dt.Rows(0)("pot_res").ToString()
            txtAppAdmit.Text = dt.Rows(0)("app_admit").ToString()
            txtReasonNotAdmitting.Text = dt.Rows(0)("reason_not_admit").ToString()
            txtAppBy.Text = dt.Rows(0)("app_by").ToString()
            txtZipCode.Text = dt.Rows(0)("zip_code").ToString()
            txtAssess.Text = dt.Rows(0)("assess").ToString()
            txtTour.Text = dt.Rows(0)("tour").ToString()
            txtHearUs.Text = dt.Rows(0)("hear_us").ToString()
            txtNameCaseMngr.Text = dt.Rows(0)("name_case_mngr").ToString()
            txtHosOrg.Text = dt.Rows(0)("hos_org").ToString()
            txtDoctor.Text = dt.Rows(0)("doctor").ToString()
            txtPatDiag.Text = dt.Rows(0)("pat_diag").ToString()
            txtPayorKey.Text = dt.Rows(0)("payor_key").ToString()
            txtPayorDetail.Text = dt.Rows(0)("payor_detail").ToString()
            txtProductKey.Text = dt.Rows(0)("product_key").ToString()
            txtDecisionKey.Text = dt.Rows(0)("decision_key").ToString()
            txtReasonKey.Text = dt.Rows(0)("reason_key").ToString()
            txtFUdate.Text = dt.Rows(0)("last_FU_date").ToString()
            txtPContact.Text = dt.Rows(0)("pri_contact").ToString()
            txtRelationship.Text = dt.Rows(0)("relationship").ToString()
            txtStreet.Text = dt.Rows(0)("street").ToString()
            txtCity.Text = dt.Rows(0)("city").ToString()
            txtState.Text = dt.Rows(0)("state").ToString()
            txtZip2.Text = dt.Rows(0)("zip").ToString()
            txtPhone.Text = dt.Rows(0)("phone").ToString()
            txtComments.Text = dt.Rows(0)("comments").ToString()
        Else
            DisplayControls(False)
        End If
        sqlConn.Close()
    End Sub


    Private Sub DisplayControls(ByVal visibility As Boolean)
        txtLocation.Visible = visibility
        txtRefDate.Visible = visibility
        pot_res.Visible = visibility
        txtAppAdmit.Visible = visibility
        txtReasonNotAdmitting.Visible = visibility
        txtAppBy.Visible = visibility
        txtZipCode.Visible = visibility
        txtAssess.Visible = visibility
        txtTour.Visible = visibility
        txtHearUs.Visible = visibility
        txtNameCaseMngr.Visible = visibility
        txtHosOrg.Visible = visibility
        txtDoctor.Visible = visibility
        txtPatDiag.Visible = visibility
        txtPayorKey.Visible = visibility
        txtPayorDetail.Visible = visibility
        txtProductKey.Visible = visibility
        txtDecisionKey.Visible = visibility
        txtReasonKey.Visible = visibility
        txtFUdate.Visible = visibility
        txtPContact.Visible = visibility
        txtRelationship.Visible = visibility
        txtStreet.Visible = visibility
        txtCity.Visible = visibility
        txtState.Visible = visibility
        txtZip2.Visible = visibility
        txtPhone.Visible = visibility
        txtComments.Visible = visibility
    End Sub
End Class

1 个答案:

答案 0 :(得分:1)

这是你需要做的:

在gridview rowcommand事件中。使用命令参数(您已设置)获取record_id。

使用此record_id

设置会话

最后执行Response.Redirect或Session.Transfer到Page2.aspx

HTH