2011-05-06 64 views
0

我正在使用此代碼進行數據列表驗證。使用某些文本和驗證數據列表綁定數據列表

我綁定在datalist中的圖像之後,我試圖給每個圖像的標題假設有3圖像是datalist然後爲第一個圖像我能夠給,但另一個我無法。我認爲在這種情況下有一些錯誤可以幫助我。代碼如下..

if (DataList1.Items.Count == 0) 
      { 
       msgError.Text = "Please add images and captions for each image"; 
       msgError.Focus(); 
      } 
     else 
      AddCaption(); 
      bool IsEmptyCaption = false; 
      Hashtable htble = (Hashtable)ViewState["imgIdCapHtbl"]; 
      List<int> imgIds = (List<int>)ViewState["imgIds"]; 

      if (htble != null && imgIds != null) 
      { 
       foreach (int id in imgIds) 
       { 
        if (htble[id] == "") 
        { 
         IsEmptyCaption = true; 
         break; 
        } 
        else 
         IsEmptyCaption = false; 

       } 
      } 
      else 
       IsEmptyCaption = true; 

      if (DataList1.Items.Count == 0) 
      { 
       msgError.Text = "Please add images"; 
       msgError.Focus(); 
      } 
      else if (IsEmptyCaption) 
      { 
       msgError.Text = "Please add captions for each image"; 
       msgError.Focus(); 
      } 
      else 
      { 
       Args[0] = "Section1"; 
       Args[1] = ""; 
       Args[2] = FindingId.ToString(); 
       Args[3] = FindingIdIns.ToString(); 
       AnotherHeading = false; 
       //AddCaption(); 
       objGetBaseCase.UpdateImageCaptions((Hashtable)ViewState["imgIdCapHtbl"]); 
       if (AddFindingsViewerDetails != null) 
        AddFindingsViewerDetails(Args, e); 
       ClearImages(); 
       PageContent pg = (PageContent)this.Parent.FindControl("PageContent"); 
       if (pg != null) 
        pg.LoadWorkflowForCase(); 
       if (Display != null) 
        Display(null, EventArgs.Empty); 
      } 
+0

請任何一個幫助我 – Rocky 2011-05-06 10:49:33

回答

0
if (DataList1.Items.Count == 0) 
     { 
      msgError.Text = "Please add images and captions for each image"; 
      msgError.Focus(); 
     } 
    else 
     AddCaption(); 
     bool IsEmptyCaption = false; 
     Hashtable htble = (Hashtable)ViewState["imgIdCapHtbl"]; 
     List<int> imgIds = (List<int>)ViewState["imgIds"]; 

     if (htble != null && imgIds != null) 
     { 
      foreach (int id in imgIds) 
      { 
       if (htble[id] == "" || htble[id] == null) // New code implemented here 
       { 
        IsEmptyCaption = true; 
        break; 
       } 
       else 
        IsEmptyCaption = false; 

      } 
     } 
     else 
      IsEmptyCaption = true; 

     if (DataList1.Items.Count == 0) 
     { 
      msgError.Text = "Please add images"; 
      msgError.Focus(); 
     } 
     else if (IsEmptyCaption) 
     { 
      msgError.Text = "Please add captions for each image"; 
      msgError.Focus(); 
     } 
     else 
     { 
      Args[0] = "Section1"; 
      Args[1] = ""; 
      Args[2] = FindingId.ToString(); 
      Args[3] = FindingIdIns.ToString(); 
      AnotherHeading = false; 
      //AddCaption(); 
      objGetBaseCase.UpdateImageCaptions((Hashtable)ViewState["imgIdCapHtbl"]); 
      if (AddFindingsViewerDetails != null) 
       AddFindingsViewerDetails(Args, e); 
      ClearImages(); 
      PageContent pg = (PageContent)this.Parent.FindControl("PageContent"); 
      if (pg != null) 
       pg.LoadWorkflowForCase(); 
      if (Display != null) 
       Display(null, EventArgs.Empty); 
     } 

現在,它的做工精細...