How to dynamically add gridview in asp.net c#

前端 未结 3 1677
无人及你
无人及你 2021-01-28 06:01

Hello guys i have to dynamically add multiple gridview in asp.net. There are no of gridview are genereated on the basis of selection.

3条回答
  •  面向向阳花
    2021-01-28 06:34

    If I have not understood wrong from title that add multiple grid view dynamically means want to add grid view from code behind at run time.

    As GridView is a class in ASP.NET C# and we can create object of it and set its properties just like other class object like follows:

    GridView objGV = new GridView();
    objGV .AutoGenerateColumns = false;
    

    and can add columns of different type like BoundField and TemplateField from code Like follows:

    BoundField field = new BoundField();
    field.HeaderText = "Column Header";
    field.DataField = Value;
    objGV .Columns.Add(field);
    

    and finally can add this grid view object on .aspx under any container control like panel.

    PanelId.Controls.Add(objGV );
    

    For adding multiple grid instance just iterate above code in loop like:

    for(int i=0;i

    Hope I understood your requirement correctly and my explanation will be helpful for you.

提交回复
热议问题