locked
Set <asp:GridView row width RRS feed

  • Question

  • User1741069310 posted

    Hi

    I want to know is a way to set row width of each rows without asp:BoundField tag?

    Thanks

    Francis SZE

    <asp:GridView ID="GridView1" CssClass="Grid" HeaderStyle-CssClass="header" runat="server" AutoGenerateColumns="true" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" OnDataBound="GridView1_DataBound" >

    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProConnectionString %>"
    SelectCommand="SELECT * FROM MS.dbo.FS where ClientId = 1 AND [Year] BETWEEN 2017 AND 2019"
    UpdateCommand="update MS.dbo.FS set AGM_Cli=@AGM_Cli Where ClientId = @ClientId and [Year] = @Year "
    OnUpdated="OnDSUpdatedHandler"
    >

    </asp:SqlDataSource>

    Wednesday, November 28, 2018 4:23 AM

Answers

  • User-271186128 posted

    Hi fsze88,

    is a way to set row width of each rows without asp:BoundField tag?

    You could use CSS selector to find the gridview table, and set the td width attribute.

    Code like this:

        <style type="text/css">
            .Grid {
                border: 1px solid black;
                table-layout: fixed;
            }
    
                .Grid th {
                    width: 300px;
                    background-color: antiquewhite;
                }
                .Grid td{
                    text-align:center;
                    width:300px;
                    background-color:aquamarine;
                }
        </style>

    and 

            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="true" CellPadding="4"
                ForeColor="#333333" GridLines="None" CssClass="Grid" HeaderStyle-CssClass="header"
                DataKeyNames="Indexid" DataSourceID="SqlDataSource1">
            </asp:GridView>

    the output as below:

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 29, 2018 5:26 AM