2012-09-07 157 views
4

我有一個窗體,其中包含一系列的文本框和複選框,填充頁面加載時從數據庫中的數據的asp.net網頁。我打算讓用戶可以自由更改文本或檢查框的值,然後按下按鈕。按下按鈕後,信息將從它們編輯的框中拉出,然後數據庫將根據所做更改進行更新。問題是,即使複選框val的文本已被更改,textbox.text和checkbox.checked仍包含最初加載到頁面加載子中的值。textbox.text仍然保留舊值更改後

這裏是我的代碼至今:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
     Dim lq2 As New lqDFDataContext 
     Dim var = lq2.admin_GetFeatured().ToList() 
     Dim i As Integer = 1 

     For Each f In var 
      If i = 1 Then 
       isChanged.featuredID1 = f.featuredID 
       title1.Text = f.title 
       text1.Text = f.text 
       imageURL1.Text = f.imageURL 
       login1.Checked = f.loginPage 
       index1.Checked = f.indexPage 
       mobile1.Checked = f.mobilePage 
       priority1.Text = Str(f.priority) 
      End If 

      If i = 2 Then 
       isChanged.featuredID2 = f.featuredID 
       title2.Text = f.title 
       text2.Text = f.text 
       imageURL2.Text = f.imageURL 
       login2.Checked = f.loginPage 
       index2.Checked = f.indexPage 
       mobile2.Checked = f.mobilePage 
       priority2.Text = Str(f.priority) 
      End If 

      If i = 3 Then 
       isChanged.featuredID3 = f.featuredID 
       title3.Text = f.title 
       text3.Text = f.text 
       imageURL3.Text = f.imageURL 
       login3.Checked = f.loginPage 
       index3.Checked = f.indexPage 
       mobile3.Checked = f.mobilePage 
       priority3.Text = Str(f.priority) 
      End If 

      If i = 4 Then 
       isChanged.featuredID4 = f.featuredID 
       title4.Text = f.title 
       text4.Text = f.text 
       imageURL4.Text = f.imageURL 
       login4.Checked = f.loginPage 
       index4.Checked = f.indexPage 
       mobile4.Checked = f.mobilePage 
       priority4.Text = Str(f.priority) 
      End If 

      If i = 5 Then 
       isChanged.featuredID5 = f.featuredID 
       title5.Text = f.title 
       text5.Text = f.text 
       imageURL5.Text = f.imageURL 
       login5.Checked = f.loginPage 
       index5.Checked = f.indexPage 
       mobile5.Checked = f.mobilePage 
       priority5.Text = Str(f.priority) 
      End If 

      If i = 6 Then 
       isChanged.featuredID6 = f.featuredID 
       title6.Text = f.title 
       text6.Text = f.text 
       imageURL6.Text = f.imageURL 
       login6.Checked = f.loginPage 
       index6.Checked = f.indexPage 
       mobile6.Checked = f.mobilePage 
       priority6.Text = Str(f.priority) 
      End If 

      i = i + 1 


     Next 
    End Sub 

    Protected Sub featuredSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles featuredSubmit.Click 
     Dim lq As New lqDFDataContext 



     If isChanged1.Checked Then 
      lq.admin_RemoveFeatured(isChanged.featuredID1) 
      lq.admin_AddFeatured(title1.Text, text1.Text, imageURL1.Text, login1.Checked, index1.Checked, mobile1.Checked, Integer.Parse(priority1.Text)) 

     End If 

     If isChanged2.Checked Then 
      lq.admin_RemoveFeatured(isChanged.featuredID2) 
      lq.admin_AddFeatured(title2.Text, text2.Text, imageURL2.Text, login2.Checked, index2.Checked, mobile2.Checked, Integer.Parse(priority2.Text)) 

     End If 

     If isChanged3.Checked Then 
      lq.admin_RemoveFeatured(isChanged.featuredID3) 
      lq.admin_AddFeatured(title3.Text, text3.Text, imageURL3.Text, login3.Checked, index3.Checked, mobile3.Checked, Integer.Parse(priority3.Text)) 

     End If 

     If isChanged4.Checked Then 
      lq.admin_RemoveFeatured(isChanged.featuredID4) 
      lq.admin_AddFeatured(title4.Text, text4.Text, imageURL4.Text, login4.Checked, index4.Checked, mobile4.Checked, Integer.Parse(priority4.Text)) 

     End If 

     If isChanged5.Checked Then 
      lq.admin_RemoveFeatured(isChanged.featuredID5) 
      lq.admin_AddFeatured(title5.Text, text5.Text, imageURL5.Text, login5.Checked, index5.Checked, mobile5.Checked, Integer.Parse(priority5.Text)) 

     End If 

     If isChanged6.Checked Then 
      lq.admin_RemoveFeatured(isChanged.featuredID6) 
      lq.admin_AddFeatured(title6.Text, text6.Text, imageURL6.Text, login6.Checked, index6.Checked, mobile6.Checked, Integer.Parse(priority6.Text)) 

     End If 

    End Sub 


End Class 

Public Module isChanged 
    Public featuredID1 As Integer 
    Public featuredID2 As Integer 
    Public featuredID3 As Integer 
    Public featuredID4 As Integer 
    Public featuredID5 As Integer 
    Public featuredID6 As Integer 
End Module 
+0

安德魯是正確的,如果你不投入,如果(不是Page.IsPostback)你總是點擊,重新加載默認值,並且這種行爲正在將新值替換爲舊的 –

回答

6

你的負載語句將在每個網頁提交表單的值,它是(Page.IsPostback!)可能會壓倒原始價值;您需要將foreach代碼包裝在If (Not Page.IsPostBack) Then .. End If聲明中。

HTH

+0

這沒什麼用,謝謝! – xxyyxx

2

把頁面加載代碼到一個如果

0

你必須嘗試進入你的頁面加載,

If (Not Page.IsPostBack) Then 
.. 
End 

爲了當您發佈DATAS不刷新

相關問題