[英]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.