Asked by:
Asp.net Web Forms GridView Dynamic Column Issue

Question
-
User-2097784254 posted
Hi,
We have a .Net Web Form application with 4.7.2 version.
When we insert column programmaticaly to GridView component, TemplateFields not rendering after postback.
We found a topic about that issue. I think this is a .Net framework bug. There is a feedback url on the post but I couldn't open that page.FeedBack url:
Topic url:
https://forums.asp.net/t/1102255.aspx?GridView+Columns+Insert+Problems
Example Code:
Aspx->
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <asp:GridView ID="TestGrid" runat="server" AutoGenerateColumns="false"> <Columns> <asp:BoundField HeaderText="Col1" DataField="Name" /> <asp:TemplateField> <HeaderTemplate> <asp:Label ID="Col2HeaderLabel" runat="server" Text="Col2"></asp:Label> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="Col2CheckBox" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="Col3" DataField="Surname" /> </Columns> </asp:GridView> <asp:Button ID="TestButton" runat="server" Text="Test" /> </asp:Content>
Aspx.cs ->protected override void OnInit(EventArgs e) { base.OnInit(e); TestGrid.Columns.Insert(0,new BoundField { HeaderText = "Dynamic Col", DataField = "Description" }); } protected void Page_Load(object sender, EventArgs e) { TestGrid.DataSource = GetList(); TestGrid.DataBind(); } private List<Info> GetList() { List<Info> list = new List<Info>(); list.Add(new Info { Description = "Row 1", Name = "Name 1", Surname = "Surname 1" }); list.Add(new Info { Description = "Row 2", Name = "Name 2", Surname = "Surname 2" }); list.Add(new Info { Description = "Row 3", Name = "Name 3", Surname = "Surname 3" }); return list; } } public class Info { public string Name { get; set; } public string Surname { get; set; } public string Description { get; set; } }
Friday, August 21, 2020 2:28 PM
All replies
-
User-943250815 posted
I the mean time what about, make gridview with additional column and show/hide such column as you need on Gridview.Databound event
Friday, August 21, 2020 4:05 PM -
User1535942433 posted
Hi yondersever,
Accroding to your description,I suggest you could post your codes to us.It will help us to solve your problem.
As far as I think, you need to loop through the DataTable, then according the DataColumns to create columns in GridView. You could use the following code to get column name from Table.
Example:
https://forums.asp.net/t/2055073.aspx?Gridview+with+Dynamic+Columns+and+Template+fields
There is a feedback url on the post but I couldn't open that page.In the article,It have some solution of Microsoft Connect. The community feedback feature of the Microsoft Connect site for SQL Server has been replicated to the SQL Server section of the Azure Feedback Forums.
1.System Center Configuration Manager and Microsoft Intune (Connect Site ID 892)
- If you have a feature request for Configuration Manager or Intune, UserVoice is still the best place for feature requests: https://configurationmanager.uservoice.com and http://microsoftintune.uservoice.com.
- If you want to file a bug against Configuration Manager, please use the Windows Feedback Hub, which is built into the Windows 10 operating system. For more information, see https://aka.ms/configmgrfeedback. You can track the status of new bugs filed in Feedback Hub, but not bugs previously filed under Connect; all bugs filed under Connect are still accessible by the product team.
- If you think you’ve found a bug with Intune, please open a support case. For more information, see https://aka.ms/intunesupport.
- If you are part of the Customer Connection Program and are trying to access content from the Configuration Manager or Intune Advisors calls, please contact your Customer Connection Program contact to get access to the new TechCommunity.
- If you are a Partner, please contact your Partner contact.
- If you are trying to get access to content for the Technical Adoption Program (TAP) please contact your TAP buddy.
2.Dynamics AX Feedback (Connect Site ID 13211)
- Dynamics 365 for Finance and Operations, Enterprise edition 7.3 with Platform update 12: https://aka.ms/finandops73pu12
- Dynamics 365 for Finance and Operations, Enterprise edition July 2017 (7.2) with Platform update 12: https://aka.ms/finandops72pu12
3.Microsoft 365 powered device/Accelerate (Connect Site ID 1031)
The updated website and downloadable materials can be found at https://aka.ms/PoweredDevice-FTprograms.
4.Microsoft Alumni Network (Connect Site ID 1379)
5.WME Conformance Testing Connection (Connect Site ID 605)
6.High Performance Computing Team (Connect Site ID 12)
Please visit https://partner.microsoft.com/en-us/solutions/practice-areas/cloud-infrastructure-management/high-performance-computing.
7.DevDiv / Visual Studio and .NET Framework (Connect Site ID 210)
We have reviewed and migrated bugs to Developer Community. For VC++ issues, please search the Developer Community site for C++ for your ConnectID or the substring of the bug title, found in an an automated email you received from the original Connect system. Please bear with us as we go through the process of triaging these issues for the new system. If you cannot locate your report, please contact vsfeedback@microsoft.com.
To report a new Visual Studio bug, please use the integrated Report a Problem feature in Visual Studio 2017. C++ compiler issues can also be filed at the Developer Community site for C++.
8.Services Connection (Connect Site ID 1067)
Please contact scrmteam@microsoft.com for the status of the program.
Best regards,
Yijing Sun
Monday, August 24, 2020 6:23 AM