2014-08-28 27 views
0

我現在正面臨着ASP.NET中的Repeater問題。當轉發器數據爲空時,ASP.NET頁面不能爲空

我將數據綁定到轉發器,該轉發器位於div可見性爲false並且顯示爲無的情況下。當我將數據綁定到中繼器,我得到兩種情況:

案例1:

當查詢返回一些數據。在這種情況下,我不會收到任何錯誤,並且每件事情都能正常運行。

CASE 2: 當查詢返回空白時。這次我得到頁面不能爲空錯誤。 (頁面不能爲空,請確保此操作正在ASP.NET請求的上下文中執行。)

請找到在該按鈕上運行的代碼單擊。

int RowCount = 0; 
string cmd = "SELECT PrjB.Prj_ID, POB.ExpType as ExpType, TExp.Expenditure_ID AS ExpID, ISNULL(PrjB.Amount_Allocated, 0) AS 
    BudgetAllocated, ISNULL(POB.AmtAllocated, 0) " 
    + "AS BudgetAvailedPO, ISNULL(NonPOB.AmtPaid, 0) AS BudgetAvailedNonPO FROM v_ProjectBudgetAllocated AS PrjB LEFT OUTER JOIN " 
    + "v_POBudgetAllocated AS POB ON PrjB.Prj_ID = POB.Proj_ID AND PrjB.Expenditure_Type = POB.ExpType LEFT OUTER JOIN " 
    + "v_NonPOBudgetAvailed AS NonPOB ON NonPOB.PrjID = PrjB.Prj_ID INNER JOIN T_Expenditure AS TExp ON POB.ExpType = TExp.Expenditure_Type " 
    + "WHERE (PrjB.Prj_ID = '" + PrjID + "') ORDER BY ExpID"; 

DataSet ds = new DataSet(); 
SqlCommand selectCmd = new SqlCommand(cmd, myConnection); 

SqlDataAdapter da = new SqlDataAdapter(selectCmd); 
da.Fill(ds); 
RowCount = ds.Tables[0].Rows.Count; 

poStep3.Visible = true; 
poStep3.Style["display"] = "block"; 

if (RowCount == 0) 
{ 
    poStep3.InnerHtml = "<b>Cannot Create Purchase Order. There is no budget allocated to this Project </b>"; 
} 
else 
{ 
    PrjBudgetDetails.DataSource = ds; 
    PrjBudgetDetails.DataBind(); 
} 

的ASPX代碼的股利是:

<div id="poStep3" class="formStep" runat="server" visible="false" style="display:none;"> 
    <fieldset> 
    <span id="poDataEntryHead" class="formHead" runat="server"> 
     Enter PO Details 
    </span> 
    <legend id="poDataEntryInstructions" class="frmInstructions" runat="server"> 
     Please fill 
     all the texts in the fields. All fields are mandatory 
    </legend> 
    <div id="MessageDiv" runat="server" class="formMsg"> 
    </div> 
    <div class="fieldgroup"> 
     <asp:Label ID="LbPOID" runat="server" Text="PO ID:" CssClass="formFieldLabel" AssociatedControlID="POIDText"> 
     </asp:Label> 
     <asp:TextBox ID="POIDText" name="PrjIDText" runat="server" CssClass="formInputField"> 
     </asp:TextBox> 
     <asp:Label ID="POIDTextDsp" Font-Bold="true" runat="server" Text="" Visible="false" 
     CssClass="formFieldLabel" Style="display: none;"> 
     </asp:Label> 
     <br /> 
    </div> 
    <div class="fieldgroup"> 
     <asp:Label ID="LbPOTitle" runat="server" Text="PO Title:" CssClass="formFieldLabel" 
     AssociatedControlID="POTitleText"> 
     </asp:Label> 
     <asp:TextBox ID="POTitleText" name="POTitleText" runat="server" CssClass="formInputField"> 
     </asp:TextBox> 
     <asp:Label ID="POTitleTextDsp" Font-Bold="true" runat="server" Text="" CssClass="formFieldLabel" 
     Visible="false" Style="display: none;"> 
     </asp:Label> 
     <br /> 
    </div> 
    <div class="fieldgroup"> 
     <asp:Label ID="LbPODesc" runat="server" Text="PO Description:" CssClass="formFieldLabel" AssociatedControlID="PODescText"> 
     </asp:Label> 
     <textarea id="PODescText" name="PODescText" cols="50" rows="6" runat="server" class="formInputField" /> 
     <asp:Label ID="PODescTextDsp" Font-Bold="true" runat="server" Text="" CssClass="formFieldLabel" 
     Visible="false" Style="display: none;"> 
     </asp:Label> 
     <br /> 
    </div> 
    <div class="fieldgroup"> 
     <asp:Label ID="LbPOIssueDateText" runat="server" Font-Bold="true" Text="PO Issue Date:" CssClass="formFieldLabel"> 
     </asp:Label> 
     <asp:TextBox ID="POIssueDateText" name="POIssueDateText" runat="server" CssClass="formInputField"> 
     </asp:TextBox> 
     <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> 
     </asp:ToolkitScriptManager> 
     <asp:CalendarExtender ID="POIssueDateText_CalendarExtender" runat="server" TargetControlID="POIssueDateText" 
     Format="MM-dd-yyyy"> 
     </asp:CalendarExtender> 
     <asp:Label ID="POIssueDateTextDsp" runat="server" Font-Bold="true" Text="" Visible="false" CssClass="formFieldLabel" Style="display: none;"> 
     </asp:Label> 
    </div> 
    <div class="fieldgroup"> 
     <asp:Label ID="LbprjBudgetInfoHead" runat="server" Font-Bold="true" Text="Project Budget data:" CssClass="formFieldLabel"> 
     </asp:Label> 
     <span id="prjBudgetInfoHead" class="formHead" runat="server"> 
     Project Budget Details 
     </span> 
     <span id="prjBudgetInfoInstructions" class="frmInstructions" runat="server"> 
     The 
     current program budget status. 
     </span> 
    </div> 
    <br /> 
    <div class="fieldgroup"> 
     <table class="tblDispData"> 
     <asp:Repeater ID="PrjBudgetDetails" runat="server" ClientIDMode="Static"> 
      <HeaderTemplate> 
      <tr> 
       <th class="thDataDisp"> 
       <asp:Label ID="LbExpType" runat="server" Text="Expenditure Type" CssClass="LbTblDataDisp" 
       Font-Bold="true"> 
       </asp:Label> 
       </th> 
       <th class="thDataDisp"> 
       <asp:Label ID="LbAllocatedBudget" runat="server" Text="Allocated Budget" CssClass="LbTblDataDisp" 
       Font-Bold="true"> 
       </asp:Label> 
       </th> 
       <th class="thDataDisp"> 
       <asp:Label ID="LbAvailedBudget" runat="server" Text="Available Budget" CssClass="LbTblDataDisp" 
       Font-Bold="true"> 
       </asp:Label> 
       </th> 
       <th class="thDataDisp"> 
       <asp:Label ID="LbRequestedBudget" runat="server" Text="Budget Requested" CssClass="LbTblDataDisp" 
       Font-Bold="true"> 
       </asp:Label> 
       </th> 
      </tr> 
      </HeaderTemplate> 
      <ItemTemplate> 
      <tr> 
       <td class="tdDataDisp"> 
       <asp:Label ID="ExpTypeText" runat="server" Text='<%#Eval("ExpType") %>' CssClass="LbTblDataDisp"AssociatedControlID="BudgetRequestedText"> 
       </asp:Label> 
       </td> 
       <td class="tdDataDisp"> 
       <asp:Label ID="BudgetAllocatedText" runat="server" Text=' <%#Eval("BudgetAllocated") %>' CssClass="LbTblDataDisp" AssociatedControlID="BudgetRequestedText"> 
       </asp:Label> 
       </td> 
       <td class="tdDataDisp"> 
       <asp:Label ID="BudgetAvailableText" runat="server" Text='<%#Convert.ToDouble(Eval("BudgetAllocated")) - Convert.ToDouble(Eval("BudgetAvailedPO")) - Convert.ToDouble(Eval("BudgetAvailedNonPO")) %>' CssClass="LbTblDataDisp" ClientIDMode="Static" AssociatedControlID="BudgetRequestedText"> 
       </asp:Label> 
       </td> 
       <td class="tdDataDisp"> 
       <asp:TextBox ID="BudgetRequestedText" runat="server" dataKey='<%#Eval("ExpID") %>' dataValue='<%#Eval("ExpType") %>' CssClass="tblDataInput" dataAmount='<%#Convert.ToDouble(Eval("BudgetAllocated")) Convert.ToDouble(Eval("BudgetAvailedPO")) - Convert.ToDouble(Eval("BudgetAvailedNonPO")) %>'></asp:TextBox> 
       </td> 
      </tr> 
      </ItemTemplate> 
     </asp:Repeater> 
     <tr> 
      <td colspan="3"> 
      <span id="Span1" class="frmInstructions" runat="server"> 
       Please enter zero(0) if not 
       requesting budget for any particular expenditure. The currency is INR. 
      </span> 
      </td> 
      <td> 
      <asp:Button ID="POSubmitBtn" runat="server" Text="Submit Budget" CssClass="formNext" ClientIDMode="Static" OnClick="POSubmitBtn_Click" /> 
      <asp:Button ID="POGoToHomeBtn" runat="server" OnClick="POGoToHomeBtn_Click" Text="Home" CssClass="formNext" Visible="false" /> 
      </td> 
     </tr> 
     </table> 
    </div> 
    </fieldset> 
</div> 

它已經幾個小時,因爲我在谷歌撞我的頭。看起來我被困在這裏,需要一些專家的幫助才能繼續前進。

在此先感謝。 -Himanshu

+0

也許設置'poStep3.InnerHtml'是問題,因爲它包含服務器控件。改爲嘗試設置'poStep3.Visble = false'。 – canon 2014-08-28 13:18:34

+0

順便說一句,應該避免內聯查詢來防止sql注入 – 2014-08-28 13:41:22

回答

0

我不知道在這裏給出答案的人是否刪除了他們或其他東西。但是有一個人在兩天前發佈了答案,並且工作。

解決方案是有另一個隱藏的div,並使其啓用,而不是更新當前div的innerHTML。

相關問題