SANDEEP
SANDEEP

Reputation: 1082

How can i place Gridview center of div or panel.?

Hello! Can anyone tell me how can I place any Gridview in center in Div or panel? I have applied following CSS but its does not working:

<asp:Panel ID="pnlGrid" CssClass="panel" runat="server">
 <div style="text-align:center">
   <asp:GridView ID="grdReqApproval" runat="server"   AutoGenerateColumns="false"     CssClass="SimpleGrid">
      <Columns>
  <asp:BoundField DataField="Approved By" HeaderText="Approved By" />
  <asp:BoundField DataField="User Name" HeaderText="User Name" />
  <asp:BoundField DataField="Approval Time" HeaderText="Approvel Time" />
</Columns>
</asp:GridView>
</div>
    </asp:Panel>
.panel
{
width: 330px;
padding: 10px;
min-height: 20px;
border: 1px solid #dcdcdc;
margin-left:auto;
margin-right:auto;
}

Upvotes: 5

Views: 39374

Answers (6)

Ata Hoseini
Ata Hoseini

Reputation: 137

.div_text_center {
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}

<div class="div_text_center">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button ID="Button1" runat="server" Text="Button" />
            <asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center">
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

enter image description here

Upvotes: 0

Ritwik
Ritwik

Reputation: 611

HorizontalAlign property of Gridview can solve your problem

    <asp:Panel ID="pID" runat="server">
     <div>
       <asp:GridView ID="gvID" runat="server" AutoGenerateColumns="false"
 HorizontalAlign="Center">
          <Columns>
             ...
             ...
          </Columns>
    </asp:GridView>
    </div>

Upvotes: 17

Thrasymakus
Thrasymakus

Reputation: 23

Slight case of thread necromancy, but I was having the same problem and managed to fix it by aligning the code block rather than the gridview itself.

Basically I set the width of the element to 40%, and left to 30% (which means right is also 30%, because maths) and that positions the whole lot, text, grid and all into the middle of the page.

The css looks roughly like this

GridExample
{
position:absolute;
left:30%;
width:40%;
padding:0;
margin:0;
}

Upvotes: 2

Pranay Rana
Pranay Rana

Reputation: 176906

Check this is working for me , Ultimatly gridview get converted to table so the apply following stylesheet to your gridview which i applied to table

CSS

.centered-table {
   margin-left: auto;
   margin-right: auto;
}

HTML

<div>
<table class="centered-table" border="1">
    <tr><td>Pekin</td> <td>Illinois</td></tr>
    <tr><td>San Jose</td><td>California</td></tr>
</table>
</div>

JsFiddle Demo

Upvotes: 2

Lotok
Lotok

Reputation: 4607

as you see here, your class works. Just be sure its parent container is wider so it can center

http://jsfiddle.net/C7ybw/

#container{
    width:800px;
    border:1px solid #000;
}

Upvotes: 0

wazaminator
wazaminator

Reputation: 245

on your div text-align: center

Upvotes: 0

Related Questions