1
我目前有一個datareader作爲我的數據源綁定到中繼器。因爲在這裏看到:中繼器控制返回null
Try
myConnection.Open()
sqlCommand = New SqlCommand(sqlText, myConnection)
dr = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection)
cropPlanRepeater.DataSource = dr
cropPlanRepeater.DataBind()
Catch ex As Exception
End Try
這將啓動數據綁定的情況下,像這樣:
Public Sub CropPlanRepeater_ItemDataBound(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles cropPlanRepeater.ItemDataBound
Dim rptI As RepeaterItem = e.Item
Dim AmttoSell = TryCast(rptI.FindControl("amtToSell"), Label)
AmttoSell.Text = AmttoSell
End Sub
出於某種原因,這FindControl方法,不斷「回零」或「無」我想看看如果在我的控制層面和缺乏控制層面上存在缺陷,但我找不到任何東西。
這裏有一個看看它是如何工作的HTML:
<asp:Repeater ID="cropPlanRepeater" runat="server" Visible="false">
<HeaderTemplate>
<tr align="center" class="top-rpt-head">
<th scope="col">
Crop
</th>
<th scope="col">
Production
</th>
<th scope="col">
Amount to Sell
</th>
<th scope="col">
Breakeven
</th>
<th scope="col">
Target Price
</th>
<th scope="col">
Target Revenue
</th>
<th scope="col">
Feed Value
</th>
<th scope="col">
Other Income
</th>
<th scope="col">
Expenses
</th>
<th scope="col">
Profit
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr align="center">
<td>
<!--- this needs to be fixed- incorrect methodology(should be done in the codebehind)----->
<%# (DataBinder.Eval(Container.DataItem, "Crop_Name"))%>
</td>
<td>
<!--- this needs to be fixed- incorrect methodology(should be done in the codebehind)----->
<%# (DataBinder.Eval(Container.DataItem, "Acres_D") * DataBinder.Eval(Container.DataItem, "Yield_D") + DataBinder.Eval(Container.DataItem, "Acres_I") * DataBinder.Eval(Container.DataItem, "Yield_I"))%>
</td>
<td>
</td>
</tr>
<asp:label runat="server" ID="AmtToSell"></asp:Label>
<asp:Literal runat="server" ID="Yield_I" Text='<%#Eval("Yield_I") %>' Visible="false" />
<asp:Literal runat="server" ID="Yield_D" Text='<%#Eval("Yield_D") %>' Visible="false" />
<asp:Literal runat="server" ID="Acres_I" Text='<%#Eval("Acres_I") %>' Visible="false" />
<asp:Literal runat="server" ID="Acres_D" Text='<%#Eval("Acres_D") %>' Visible="false" />
<asp:Literal runat="server" ID="Storage" Text='<%#Eval("Storage") %>' Visible="false" />
<asp:Literal runat="server" ID="Fed" Text='<%#Eval("Fed") %>' Visible="false" />
<asp:Literal runat="server" ID="Bartered" Text='<%#Eval("Bartered") %>' Visible="false" />
<asp:Literal runat="server" ID="Profit_I" Text='<%#Eval("ProfAcre_I") %>' Visible="false" />
<asp:literal runat="server" ID="Profit_D" Text='<%#Eval("ProfAcre_D") %>' Visible="false" />
</ItemTemplate>
</asp:Repeater>
我試圖把標籤內和表外,並沒有用。我不確定我的HTML或代碼隱藏是否存在問題。我需要通過代碼隱藏中的計算來操作標籤「amttosell」。 (我會做這樣的事情amttosell.text = 從數據庫中獲取的數據進行一些計算/上隱藏的標籤上面
任何幫助發佈將不勝感激。
完美運作!非常感謝! – Strohlaj