locked
Gridview RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below code . I want to centre cell horizontally . Secondly how to display checkbox with it

    I tried this but not working - cell.HorizontalAlign = HorizontalAlign.Center;

    GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
    TableHeaderCell cell = new TableHeaderCell();
    cell.Text = "col1";
    cell.ColumnSpan = 1;
    row.Controls.Add(cell);

    Thanks

    Monday, August 6, 2018 12:23 PM

All replies

  • User-492460945 posted

    Hi,

    Below is the way you can do to align text in a grid view cell.

    e.Row.Cells[5].Style["text-align"] = "center";

    For checkbox, you can directly add checkbox control in the itemtemplate of the gridview. Did you try?

    Thanks,

    RajeshV.

    Monday, August 6, 2018 12:38 PM
  • User-1499457942 posted

    Hi

      Since i have to merge some columns . I am trying below code. Is it possible that from 8 column i want to merge next 12 columns into two 

    protected void OnDataBound(object sender, EventArgs e)
            {
                GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
                TableHeaderCell cell = new TableHeaderCell();
                cell.Text = "ChkAll";
                cell.ColumnSpan = 1;
                row.Controls.Add(cell);
    
                cell = new TableHeaderCell();
                cell.ColumnSpan = 1;
                cell.Text = "Sr.";
                row.Controls.Add(cell);
    
                cell = new TableHeaderCell();
                cell.ColumnSpan = 1;
                cell.Text = "Type";
                row.Controls.Add(cell);
    
                cell = new TableHeaderCell();
                cell.ColumnSpan = 1;
                cell.Text = "Name";
                row.Controls.Add(cell);
    
                cell = new TableHeaderCell();
                cell.ColumnSpan = 1;
                cell.Text = "Department";
                row.Controls.Add(cell);
    
                cell = new TableHeaderCell();
                cell.ColumnSpan = 1;
                cell.Text = "Amount";
                row.Controls.Add(cell);
    
                cell = new TableHeaderCell();
                cell.ColumnSpan = 1;
                cell.Text = "Fixed %";
                row.Controls.Add(cell);
    
    
                cell = new TableHeaderCell();
                cell.ColumnSpan = 6;
                cell.Text = "N";
                cell.HorizontalAlign = HorizontalAlign.Center;
                row.Controls.Add(cell);
    
                cell = new TableHeaderCell();
                cell.ColumnSpan = 6;
                cell.Text = "R";
                cell.HorizontalAlign = HorizontalAlign.Center;
                row.Controls.Add(cell);
                gvwBfbStructure.HeaderRow.Parent.Controls.AddAt(0, row);
            }

    Thanks

    Monday, August 6, 2018 12:43 PM
  • User-492460945 posted

    the column 5 is just an example. you can use it to any column like Cells[x].

    Monday, August 6, 2018 12:46 PM
  • User-1171043462 posted

    To Add CheckBox to GridView header, refer

    Check Uncheck all CheckBoxes in ASP.Net GridView using jQuery

    Monday, August 6, 2018 6:32 PM