2012-04-11 3 views
0

는 u는 내가 콤보 상자에서 데이터베이스 이름을 설정 마스터 페이지의 콤보와 함께 무엇을 할 수 있는지 설명 할 수와 내가 코드가 아래콤보를 선택 지수는

 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

+0

무엇이 문제입니까? 하위 페이지에서 세션 변수를 가져 오지 않습니까? – ray

+0

yes 마스터 페이지가로드 될 때마다 텍스트가 기본값 "select"로 변경 될 때 –

+0

페이지가 아닌 페이지로 리디렉션 될 때 세션 데이터가 하위 페이지로 들어 가지 않습니다. –

답변

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 
} 


} 

이제 하위 페이지에서 동일한 세션 확인 및 백백 값을 수행하십시오. 나는 그것이 설정되기 전에 자식 페이지가 세션 변수에 액세스하려고하는 마스터 페이지의 코드를 실행하는 것이 약간의 시간 차이라고 생각한다. 따라서 세션을 확인하고 두 번 다시 게시하도록 게시하십시오.