Search code examples
c#asp.netascx

GridView Template Help


I have a grid view, that has repeating controls, with template fields that i'm currently learning and researching about.It includes a label and a drop down list.

The labels are bound to a type column from a view in the database, and the drop down with names. I can access and display the types and the names correctly. But what i want to achieve is that as soon as a user assigns a name to any one of the types(there are only 3 specific types, with options to add other types if needed).

There should be another row created with the same type, but with unassigned values(I'm able to get unassigned values to the control as well). For ex- the Types are A,B and C, so as soon as a user assigns a value to A, so another row with the of Type A should be created with unassigned values. I understand the concepts of postbacks but i'm not able to get to where i want.

How do i go about detecting and selecting type on postback from the drop down list? Should i check for each gridview row? I'm just beginning with template controls and postbacks.

Using C# and aspx, and ascx controls

All help would be much appreciated. I hope i'm clear with my question


Solution

  • For detecting the change, you'll want to tap into the SelectedIndexChanged event of the dropdown. Within that event method, you can get a reference to that dropdown's parent (which will be its gridviewrow). Then you can insert a new row into that table beneath the original one and set the values to whatever you need.