5

I want to set colspan for the header row in the grid view to look the same as on the image below:

alt text

Html code is:

<html>
    <body>
        <table border="1">
        <tr>
            <th colspan=2>Header</th>
        </tr>
        <tr>
            <td>row 1, cell 1</td>
            <td>row 1, cell 2</td>
        </tr>
        <tr>
            <td>row 2, cell 1</td>
            <td>row 2, cell 2</td>
        </tr>
        </table>
    </body>
</html>

I don't know how to create the same effect in the asp.net and I don't want to create the table by hand using for loops.

Thank you!

2
  • 2
    hey have you tried <asp:Repeater> ? Commented Oct 19, 2010 at 7:21
  • I would like to avoid the repeater. If this is not supported by GridView, then I'll have to use the repeater :( Commented Oct 19, 2010 at 7:23

2 Answers 2

10

I attached to the PreRender event:

protected void GridView1_PreRender(object sender, EventArgs e)
{
    var gridView = (GridView) sender;
    var header = (GridViewRow) gridView.Controls[0].Controls[0];

    header.Cells[0].Visible = false;
    header.Cells[1].ColumnSpan = 2;
    header.Cells[1].Text = "Header";
}
Sign up to request clarification or add additional context in comments.

Comments

-1
protected void btnAction_Click(object sender, EventArgs e)
{
    string value = txtDetails.Text;
    char[] delimiter = new char[] { ';','[' };
    string[] parts = value.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
    for (int i = 0; i < parts.Length; i++)
    {
        txtFName.Text = parts[0].ToString();
        txtLName.Text = parts[1].ToString();
        txtAge.Text = parts[2].ToString();
        txtDob.Text = parts[3].ToString();
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.