因此,我在 VS 2010 中使用 ASP.NET LINQ to SQL 网站模板。我的网站按预期运行,但我正在尝试进行一些超出我想象的自定义。最初向用户呈现两个选择...
部门 | 雇员
根据他们的选择,他们会看到一个页面,他们可以在其中插入新项目(部门或员工)。这是我的问题...
如果我单击 Departments 并选择 Department_A,我会看到 Department_A 中的所有员工,并且我知道我正在查看 Department_A,因为页面顶部的组合框显示了这一点。此时我选择插入新项目,保存我的新员工,然后我被带回“所有”部门,而不是回到我刚刚离开的 Department_A。我的目标是,如果他们需要为同一部门添加多个员工,则不必让某人点击返回部门。
有任何想法吗?
解决方案: 这是用于实现我的目标的代码,在 Insert.aspx.vb 中......
Protected table As MetaTable
Public Shared Function getPassedVars() As String
Dim oParams As String = ""
Dim qString As String = ""
Dim oSplit As New List(Of String)
Try
With HttpContext.Current
qString = .Request.Url.Query
If qString.Length > 0 Then 'do we have any passed variables?
oSplit.AddRange(qString.Split("&"))
For i As Integer = 0 To oSplit.Count - 1
oParams &= String.Format("{0}{1}", oSplit.Item(i), IIf(i < oSplit.Count - 1, ";", ""))
Next
Return oParams
Else
Return Nothing
End If
End With
Catch ex As Exception
Return Nothing
End Try
End Function
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
table = DynamicDataRouteHandler.GetRequestMetaTable(Context)
FormView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context))
DetailsDataSource.EntityTypeName = table.EntityType.AssemblyQualifiedName
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Title = table.DisplayName
End Sub
Protected Sub FormView1_ItemCommand(ByVal sender As Object, ByVal e As FormViewCommandEventArgs)
If e.CommandName = DataControlCommands.CancelCommandName Then
Response.Redirect(table.ListActionPath + getPassedVars())
End If
End Sub
Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)
If e.Exception Is Nothing OrElse e.ExceptionHandled Then
Dim urlVars As String
For Each s As String In Request.QueryString
urlVars = "?" & (s & "=") + Request.QueryString(s)
Next
Response.Redirect(table.ListActionPath & urlVars)
End If
End Sub
结束类