简体   繁体   中英

Dynamically Add TemplateField to Details View

I have a grid view that, on selected index, will populate a details view. If the selected index happens to have multiple IP Address's I want to add additional fields to display them. They don't need to be databound since I know the data. I'm using the code below to create the additional template fields. This is done in the Data Binding event.

This works until I select a different row in the grid view, then no data is displayed in the details view. My theory is that it's trying to bind the data but there are a different amount of values returned from the database than controls to put them in. I guess is there an easier way to do this?

// Check for multiple IP
countIP = devicesDetails_CountIP(devicesDataKey);

if (countIP > 1)
{
  TemplateField IPAddress2 = new TemplateField();
  devicesDetailsView.Fields.Insert(0, IPAddress2);
}

最近我遇到了这个问题,所以这里有一个链接可能对未来的访问者有所帮助从代码隐藏创建DetailsView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM