C# 如何引用多列列表中的列<&燃气轮机;并在FindControl中使用列值
FindControl正在引发空引用异常。我必须引用一个包含 控件id要在页中匹配,但使用包含 控件的名称。我试图创建一个结构,但仍然抛出异常。我知道我想做什么,以及如何做。有人能帮忙吗 我尝试了许多FindControl的变体,但它只适用于direct 对div id(FirstName)的引用请参见我的代码。我把每件事都注释掉了 但此时正在引发异常的FindControlC# 如何引用多列列表中的列<&燃气轮机;并在FindControl中使用列值,c#,asp.net,list,C#,Asp.net,List,FindControl正在引发空引用异常。我必须引用一个包含 控件id要在页中匹配,但使用包含 控件的名称。我试图创建一个结构,但仍然抛出异常。我知道我想做什么,以及如何做。有人能帮忙吗 我尝试了许多FindControl的变体,但它只适用于direct 对div id(FirstName)的引用请参见我的代码。我把每件事都注释掉了 但此时正在引发异常的FindControl <div class="form-group" visible="false" id="FirstName" ru
<div class="form-group" visible="false" id="FirstName" runat="server">
<div class="col-xs-12 col-md-8 col-sm-10 nill">
<asp:Label ID="lblFirstName" runat="server" AssociatedControlID="txtFirstName" Text="First name *" CssClass="control-label" />
<br />
<asp:TextBox ID="txtFirstName" runat="server" CssClass="form-control" MaxLength="50" aria-label="First name" required="required" AutoPostBack="true"></asp:TextBox>
<span class="required"></span>
</div>
</div>
<br />
</td>
<td>
//////////////////////////////////////
struct providerList {
public int fieldId;
public string fieldRequired;
public string aspName;
public string aspType;
}
private void loadform(List<ProviderInRequest> providerList)
{
for (int i = 0; i < providerList.Count; i++)
{
Control ctrl = FindControl(aspName); // does not work here I am trying to use column aspName value throws null reference exception
}
//TextBox txt = (TextBox)Page.FindControl(aspName);
// Target Div tag for plan
/* Control ctrl = Page.FindControl("div" + aspName);
// set visible to true if we found it.
if(ctrl != null)
{
//set div to visible
ctrl.Visible = true;
// set label to proper text
Label lbl = (Label)Page.FindControl("lbl" + aspName);
lbl.Text = displayName;
// set required for each input.
switch (aspType)
{
case "txt":
TextBox txt = (TextBox)Page.FindControl("txt" + aspName);
if(fieldRequired){
txt.Attributes.Add("required","required");
}
else{
txt.Attributes.Remove("required");
}
break;
case "ddl":
DropDownList ddl = (DropDownList)Page.FindControl("ddl" + aspName);
if(fieldRequired){
ddl.Attributes.Add("required","required");
}
else{
ddl.Attributes.Remove("required");
}
break;
*/
//////////////////////////////////////
结构提供程序列表{
公共int字段ID;
需要公共字符串字段;
公共字符串名称;
公共字符串类型;
}
专用无效加载表单(列表提供程序列表)
{
for(int i=0;i