0

マスターページのコンボボックスで何ができるか説明してもらえますかコンボボックスにデータベース名を設定し、子ページを介して呼び出しますコードは以下のとおりです

        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

インデックス変更イベントを選択

セッション ("CMBID") = cbDataBaseList.Text

4

1 に答える 1

0

上記のコードは、マスター ページの 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
 }


}

ここで、セッションで同じチェックを行い、子ページで値をポスト バックします。子ページが設定される前にセッション変数にアクセスしようとしているのは、マスターページでコードを実行するわずかな時間差だと思います。そのため、セッションを確認してポストバックし、念のため確認してください。

于 2012-04-12T10:17:47.550 に答える