我现在面临ASP.NET中的Repeater问题。
我将数据绑定到div中的转发器,其中可见性为false且显示为none。当我将数据绑定到转发器时,我得到两种情况:
案例1:
当查询返回一些数据时。在这种情况下,我没有得到任何错误,每件事都运行正常。
案例2: 查询返回空白时。这次我得到Page不能为空错误。 (页面不能为空。请确保在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();
}
div的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 :(得分:0)
我不知道在这里给出答案的人是否删除了他们或其他东西。但是有一个人在两天前发布了这个答案并且有效。
解决方案是使用另一个隐藏的div并使其启用而不是更新当前div的innerHTML。