[英]My find control isn't finding a label in gridview item template, any ideas how can I fix this?
我試圖使用與我多次使用的相同技術將值附加到我的gridview的標簽上,即使在此頁面中也是如此,但是find控件無法找到該標簽。 有誰知道為什么會這樣嗎? 從我完成的研究中,我遇到了一些情況,其中在一個項目模板中有2個標簽會導致此問題,但在某些情況下卻不會。
網格視圖:
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblStockDetailsS" runat="server"></asp:Label>
<asp:Label ID="lbl7" runat="server" Text="hello"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
后面的代碼:
Label lblSD = (Label)e.Row.FindControl("lblStockDetailsS");
lblSD.Text = Sline.StockDetailsS;
Label lblSD2 = (Label)e.Row.FindControl("lbl7");
lblSD2.Text = Sline.NLocalStock;
將您的代碼塊放在這種情況下。
if(e.Row.RowType == DataControlRowType.DataRow)
參考: https : //techpattarai.com/findcontrol-onrowdatabound-csharp/
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.