我正在尋找更新XML文檔中的某些標籤文本。循環遍歷標籤並更改值c#
標籤被命名爲supName1
,supName2
等
我有一個用於其在List.Count的所有XML節點貫穿循環。
var n = list.Count;
for (int i = 0; i < n; i++)
我需要更新每個list.count的標籤文本,但我不知道如何引用標籤。
從我的VBA經驗來看,這將是類似於"supName"+i
但我無法弄清楚的C#。
我試過以下;
var label = (Label)Controls["supName" + i];
但試圖按如下方式使用它時返回null;
label.Text = list[i].Attributes["name"].Value;
使用[Control.ControlCollection.Find(http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.find%28VS.80%29。 aspx),例如'this.Controls.Find($「supName {i}」,true)作爲標籤;' – Equalsk
這是windows窗體,wpf還是其他一些UI框架?請使用適當的標籤。 –
Windows窗體 - 在初始文章上標記爲winforms。對不起,有任何困惑。 –