Link to home
Start Free TrialLog in
Avatar of mmassy
mmassy

asked on

Create GridView Dynamically

I have a DataTable containing records. The table contains 2 columns - Questions and Type, so I want my GridView to have just these 2 columns. However,
If Type value of the Question is 1, I want to place a text box in Type column for that question.
If Type value of the Question is 2, I want to place a check box on so on.

For example, my grid should look similar to
Question1               Textbox
Question2               Checkbox
Question3               Checkbox
Question4               RadioButtonList  etc...

How could I do this dynamically in C#.  Thanks in advance..
ASKER CERTIFIED SOLUTION
Avatar of Melih SARICA
Melih SARICA
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mmassy
mmassy

ASKER

Thanks man... below is some code to make the solution clear.

//Create Text Box
if (e.Row.Cells[1].Text = "1")
{
    TextBox txt = new TextBox()
    e.Row.Cells[1].Controls.Add(txt);
} 

Open in new window