组合框选择索引已更改,将其放入母版页的会话中



你能解释一下我可以用母版页的组合框做什么吗 我在组合框中设置数据库名称并通过子页面调用代码如下尝试

        sqlConn = New SqlConnection(strConn)
        sqlConn.Open()
        Dim sqlda1 As SqlClient.SqlDataAdapter
        Dim sqlds1 As New DataSet
        sqlQry = "EXEC sp_databases"
        sqlda1 = New SqlDataAdapter(sqlQry, sqlConn)
        sqlda1.Fill(sqlds1, "DataBaseList")
        sqlConn.Close()
        Session.Add("dscb", " ")
        Session.Add("dscb", sqlds1.Tables("DataBaseList"))
        Dim IntPCount As Integer
        IntPCount = sqlds1.Tables("DataBaseList").Rows.Count
        'IntPCount = Session("dscb")
        Dim PCol As String
        ' cbDataBaseList.Items.Clear()
        cbDataBaseList.Items.Clear()
        cbDataBaseList.Text = "Select"
        For p = 0 To IntPCount - 1
            PCol = sqlds1.Tables("DataBaseList").Rows(p).Item("DATABASE_NAME").ToString
            If PCol.Length > 5 Then
                If PCol <> "master" Or PCol <> "msdb" Or PCol <> "tempdb" Then
                    Dim strDataBaseName As String = PCol
                    strDataBaseName = strDataBaseName.Remove(4)
                    '*** Add only "Customer's" which got the prefix "CLT_ " ***
                    If strDataBaseName = "CLT_" Then
                        NewPCol = PCol.Replace("CLT_", "")
                        NewPCol.Trim()
                        'cbDataBaseList.Items.Add(NewPCol)
                        cbDataBaseList.Items.Add(NewPCol)
                    End If
                End If
            End If
        Next
                Session.Add("CMBID", "")
        'cbDataBaseList.Text = NewPCol.ToString
        sqlds1.Dispose()
    Catch ex As Exception
        strex = ex.Message
        'MessageBox.Show(strex, "General form exception message 5.", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If

选择索引更改事件

Session("CMBID") = cbDataBaseList.Text

上面提到的代码是母版页的 Page_Load() 函数吗?如果是,那么您必须先检查

// Check if it has already been set.
if(Session("CMBID") != null) 
{
// Now if it is set, get the value
 String cmbid = (String) Session("CMBID");
//Get the post back value of the combo box  also
String cmbval = Request["<your control name>"];
// Make the above code of setting the combo box value as a separate function
FillComboBoxFromDB();
etif(!cmbval.Equals(cmbid))
{
   // set the session value with the new selected value
   Session("CMBID") = cmbval
 }

}

现在,在子页面中执行相同的签入会话和回发值。我想在母版页中执行代码的时差很小,子页面在设置会话变量之前尝试访问会话变量。因此,只需检查会话并回发即可加倍确定。

最新更新