2013-09-23 71 views
0

我是新來的這個編程領域(ASP.NET VB),我想知道如果有人有我的一腳踢開始,這樣我就可以讓我的事情在我的末端移動我將不勝感激!我目前正在使用代碼在Gridview中選擇整行(PatientName & Room),而沒有「選擇」按鈕(下圖)。然後我想將這些從行中傳遞到下一頁。接收頁面將包含兩個標籤。這是我迷失的地方。選擇Gridview行 - 發送到下一個頁面

我知道這裏有一些例子,但我找不到適合我的例子,除非有人能指出我正確的方向。謝謝

Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated 
    'Allows you to "select"/Highlight a row without a select button 

    If e.Row.RowType = DataControlRowType.DataRow Then 
     e.Row.Attributes("onmouseover") = "this.style.cursor='pointer';this.style.backgroundColor = '#87CEFF';" 
     e.Row.Attributes("onmouseout") = "this.style.textDecoration='none';this.style.backgroundColor = '#FFFFFF';" 
     e.Row.ToolTip = "Click to select row" 
     e.Row.Attributes("onclick") = Me.Page.ClientScript.GetPostBackClientHyperlink(Me.GridView1, "Select$" & e.Row.RowIndex) 
    End If 

End Sub 

回答

0

我強烈建議包括一個選擇按鈕。它觸發的選擇事件將爲您提供查找要在下一頁顯示的數據所需的全部信息。

至於數據的傳遞,QueryString是最好的。如果你不想讓它在URL中可用(並且不想加密或以其他方式混淆它),Session將是我的第二選擇。

0

您可以通過幾種方法完成此操作。這只是獲得你需要的一種方法。假設你有以下數據結構。

Public Class Patient 
    Private patient_Id As Integer 
    Public ReadOnly Property PatientID As Integer 
     Get 
      Return patient_Id 
     End Get 
    End Property 
    Public Property PatientName As String 
    Public Property Room As Integer 
    Public Sub New(_patientId As Integer, ByVal _PatientName As String, ByVal _Room As Integer) 
     patient_Id = _patientId 
     PatientName = _PatientName 
     Room = _Room 
    End Sub 
End Class 

我們需要一個PatientID輕鬆地從列表中,數組等。在找到一個病人你GridView你可以添加一個HiddenField與你的病人的ID,如下所示:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> 
    <Columns> 
     <asp:TemplateField HeaderText="Patient Name"> 
      <ItemTemplate> 
       <asp:HiddenField runat="server" ID="hiddenPatientID" Value='<%# Eval("PatientID")%>' /> 
       <asp:Label ID="lblPatientName" runat="server" Text='<%# Eval("PatientName")%>'></asp:Label> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Room"> 
      <ItemTemplate> 
       <asp:Label ID="lblPatientRoom" runat="server" Text='<%# Eval("Room")%>'></asp:Label> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

這將使您的患者ID可供您使用。您也可以從您的病人(PatientName,PatientRoom)訪問其他信息,爲此示例使用PatientID。您從代碼中訪問這些數據背後的方式,是通過implemmenting的RowDataBound事件您GridView控制的,就像這樣:

Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound 
    If e.Row.RowType = DataControlRowType.DataRow Then 
     Dim selectedPatient As Integer = -16 

     selectedPatient = DirectCast(e.Row.Cells(0).FindControl("hiddenPatientID"), HiddenField).Value 

     If selectedPatient > 0 Then 
      e.Row.Attributes("onclick") = Response.Redirect("~/MyOtherPage.aspx?&PatientID=" & selectedPatient) 
     End If 
    End If 
End Sub 

簡單,使用該行的FindControl功能,您可以訪問HiddenField的數據,這在這種情況下,你的病人的身份證件。您可以在下一頁使用此ID來獲取患者(getPatientById方法?),或者您可以直接使用患者的數據。

相關問題