0

假设我有两个 .aspx 页面和一个连接 sql server 数据库引擎。

第一页,我们称它为 playground.aspx,我有一组数据绑定,它使用 SELECT 函数的存储过程(使用数据集)。

现在在第二页,我们称之为link.aspx,有两个文本框,假设playground.aspx 页面中有多个数据,我想检索实体代码和用户名数据(从playground.aspx 的数据绑定中)并显示它在 link.aspx 的文本框中。

我怎样才能做到这一点?我被告知要创建一些函数,但我之前从未处理过数据绑定,只有 TextBox 和 Label,这让我很困惑。

任何帮助表示赞赏,谢谢。

编辑(这是数据绑定代码)

 <asp:Panel ID="PanelDGV" runat="server" Height="100%" ScrollBars="None" Width="100%">
                                        <asp:GridView ID="DGV" runat="server" AutoGenerateColumns="False" GridLines="None"
                                            AllowPaging="true" PageSize="2" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
                                            <Columns>
                                                <asp:BoundField DataField="EntityCode" HeaderText="Entity Code" />
                                                <asp:BoundField DataField="UserName" HeaderText="Username" />
                                                <asp:BoundField DataField="DivCode" HeaderText="Div Code" />
                                                <asp:BoundField DataField="GroupCode" HeaderText="Group Code" />
                                                <asp:BoundField DataField="CreatedBy" HeaderText="Created By" />
                                                <asp:BoundField DataField="CreatedOn" HeaderText="Created On" />
                                                <asp:BoundField DataField="ModifiedBy" HeaderText="Modified By" />
                                                <asp:BoundField DataField="ModifiedOn" HeaderText="Modified On" />
                                                <asp:ButtonField ButtonType="Image" ImageUrl="../Support/Image/Edit.png" ItemStyle-HorizontalAlign="Center"
                                                    CommandName="CmdEdit" HeaderText="Edit">
                                                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                                </asp:ButtonField>
                                            </Columns>
                                            <PagerStyle CssClass="pgr"></PagerStyle>
                                            <AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
                                        </asp:GridView>
                                    </asp:Panel>
4

1 回答 1

0

我刚刚解决了问题,这是代码

对于链接.vb

Public Function F01_sysUser_Select(ByVal EntityCode As String, ByVal Username As String) As ProcessResult
    Try
        Dim SqlCmd As New SqlCommand()
        SqlCmd.Connection = New SqlConnection(CF.CfgConnectionString)
        SqlCmd.CommandType = CommandType.StoredProcedure
        SqlCmd.CommandTimeout = CF.CfgCommandTimeout
        SqlCmd.CommandText = "sysUser_SelectByID"
        SqlCmd.Parameters.Add("@EntityCode", SqlDbType.VarChar) : SqlCmd.Parameters(0).Value = EntityCode

        SqlCmd.Connection.Open()

        Dim Dr As SqlDataReader = SqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
        F01_Dt_sysUser.Clear()
        F01_Dt_sysUser.Load(Dr)

        If F01_Dt_sysUser.Rows.Count > 0 Then
            Dr.Close()
            Dr = Nothing
            SqlCmd.Dispose()
            Return ProcessResult.SuccessWithResult
        Else
            Dr.Close()
            Dr = Nothing
            SqlCmd.Dispose()
            Return ProcessResult.SuccessWithNoResult
        End If

    Catch ex As Exception
        InsertErrorLog("PlaygroundLink.F01_sysUser_Select", ex.Message)
        ExMessage = ex.Message
        Return ProcessResult.Failed
    End Try

End Function

并在link.aspx.vb 中:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim QSEntityCode As String
    Dim QSUserName As String
    QSEntityCode = Request.QueryString("QSEC").ToString
    QSUserName = Request.QueryString("QSUN").ToString

    Dim Bl As New PlaygroundLink
    If Bl.F01_sysUser_Select(QSEntityCode, QSUserName) = CF.ProcessResult.SuccessWithResult Then
        TbEntityCode.Text = QSEntityCode
        TbUsername.Text = QSUserName
    Else
        ' LblMessage.Text = Bl.ExMessage
    End If
End Sub

最后在 playground.aspx.vb 中:

Private Sub DGV_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles DGV.RowCommand
    If e.CommandName = "CmdEdit" Then
        Dim QSEntityCode As String
        Dim QSUserName As String
        Dim idx As Integer = Convert.ToInt32(e.CommandArgument)
        Dim row As GridViewRow = DGV.Rows(idx)
        QSEntityCode = row.Cells(0).Text
        QSUserName = row.Cells(1).Text
        Response.Redirect(RR.PlaygroundLink & "?QSEC=" & QSEntityCode & "&QSUN=" & QSUserName)
    End If
End Sub

之后,我得到了我想要的,在 link.aspx 文本框中显示结果,干杯!:)

于 2013-04-29T03:49:42.197 回答