none
Sharepoint 2010 custom Visual Webpart GridView page style top border and column width

    问题

  • Hi,

    I have a gridview in my webpart and wanted to ask how one can remove that top-border above the page numbers? Also, I want the page numbers to align right which is fine, but the column width only goes as far as the field text length. how can I adjust this? Thanks

    D

    2012年6月10日 15:02

答案

  • Here is what I did to remove the border from the greidview header.

    1. Set BorderWidth="0" for gridview.

    2. Created the css file "style.css" and registered the resource as "embedded resource" in my usercontrol. Refered:http://weblogs.asp.net/abdullaabdelhaq/archive/2009/09/26/how-to-embedded-stylesheet-file-with-custom-control.aspx

    style.css contains:

    tr.top td { border-top: 1px solid silver; border-left: 1px solid silver; border-right: 1px solid silver; } 
    tr.bottom td { border-bottom: 1px solid silver; }

    3.  Added the code in PreRender of my control. This code will draw the border only on the data rows.

    protected override void OnPreRender(EventArgs e) 
            { 
                // Do as usual 
                base.OnPreRender(e); 
                int totalRow = Rows.Count; 
                int i = 0; 
                // Adjust each data row 
                foreach (GridViewRow r in Rows) 
                { 
                    i++; 
                    // Get the appropriate style object for the row 
                    TableItemStyle style = GetRowStyleFromState(r.RowState); 
     
                    // Add script code to enable selection 
     
     
                    if (i == totalRow) 
                    { 
                        r.CssClass = "top bottom row"; 
                    } 
                    else 
                    { 
                        r.CssClass = "top row"; 
                    } 
                } 
            }

    Here is what I did to remove the border from the greidview header.

    1. Set BorderWidth="0" for gridview.

    2. Created the css file "style.css" and registered the resource as "embedded resource" in my usercontrol. Refered:http://weblogs.asp.net/abdullaabdelhaq/archive/2009/09/26/how-to-embedded-stylesheet-file-with-custom-control.aspx

    style.css contains:

    tr.top td { border-top: 1px solid silver; border-left: 1px solid silver; border-right: 1px solid silver; } 
    tr.bottom td { border-bottom: 1px solid silver; }

    3.  Added the code in PreRender of my control. This code will draw the border only on the data rows.

    protected override void OnPreRender(EventArgs e) 
            { 
                // Do as usual 
                base.OnPreRender(e); 
                int totalRow = Rows.Count; 
                int i = 0; 
                // Adjust each data row 
                foreach (GridViewRow r in Rows) 
                { 
                    i++; 
                    // Get the appropriate style object for the row 
                    TableItemStyle style = GetRowStyleFromState(r.RowState); 
     
                    // Add script code to enable selection 
     
     
                    if (i == totalRow) 
                    { 
                        r.CssClass = "top bottom row"; 
                    } 
                    else 
                    { 
                        r.CssClass = "top row"; 
                    } 
                } 
            }

    shobhitkala

    2012年6月10日 16:36