asp.net simple code set GridView Adaptive column width without distortion implementation ideas and code _ practical skills

Source: Internet
Author: User
Dynamically bound GridView because the number of columns is not fixed, and there are too many columns (the blogger does this project has 150 or so fields), so set the GridView fixed width can not meet the demand. Two methods are arranged to achieve the effect of the GridView Adaptive column width without distortion.
. aspx.cs
Copy Code code as follows:

Set in an event that is bound by the row data of the GridView
protected void Gvobjectlist_rowdatabound (object sender, GridViewRowEventArgs e)
{
if (E.row.rowtype = = Datacontrolrowtype.datarow | | e.row.rowtype = = datacontrolrowtype.header)
{
Keep Column not deformed
for (int i = 0; i < E.row.cells.count; i++)
{
Method One:
E.row.cells[i]. Text = "" + e.row.cells[i]. Text + "";
E.row.cells[i]. Wrap = false;
Method Two:
E.row.cells[i]. Text = "<nobr>" + e.row.cells[i]. Text + "</nobr>";
}
}
}

Method one is to set the cell's automatic line-wrapping property to False, method two is to use HTML tag way to achieve no change line; is a space, you can make the grid line and the contents of the inside to maintain a certain distance to keep beautiful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.