0

I have a GridView that displays the Approvers list. As shown in below image. I need to show CheckBoxes, if there are multiple Approvers in a column. Is it possible? If yes then how can I achieve it?

enter image description here

E.g The Approvers section has multiple Approver Names in the first row, for which I should show CheckBoxes.

The data displayed in the grid is available in a DataTable and the multiple Approvers are part of a single row hence I can't use TemplateField and display CheckBoxes.

Ishan
  • 4,008
  • 32
  • 90
  • 153
  • I think you need to elaborate more on how you are generating the GridView. – VDWWD Jul 26 '17 at 17:57
  • @VDWWD The grid is bind to DataTable which has all the information in exact same format. I have only done grouping for Business Unit column. The approver names are ; seperated. – Ishan Jul 26 '17 at 19:32
  • where is your gridview code –  Jul 27 '17 at 11:01

1 Answers1

0

Below is the solution. I could achieve this in method OnRowDataBound(). Not sure if this is the best way.

protected void grdApproverDetails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string ApproverName  = ((Label)e.Row.Cells[2].FindControl("lblANgrd")).Text;

                string[] approvers = ApproverName.Split(';');
                if (approvers.Count() > 1)
                {
                    ((Label)e.Row.Cells[2].FindControl("lblANgrd")).Text = "";

                    int i = 0;
                    foreach (var item in approvers)
                    {
                        CheckBox ckb = new CheckBox();
                        ckb.Text = item;
                        ckb.ID = i.ToString();
                        ckb.ID = "approvernamesdynamic_"+i.ToString();
                        ckb.Checked = true;
                        e.Row.Cells[2].Controls.Add(ckb);
                        i++;
                    }
                }

            }
        }
Ishan
  • 4,008
  • 32
  • 90
  • 153