Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

css

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;
}
like image 230
SANDEEP Avatar asked Apr 18 '13 13:04

SANDEEP


People also ask

How do you align a division to the center?

You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.

How do you place an element in the center?

Center Align Elements To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.

How do I center GridView in flutter?

There is a very simple way. Just set shrinkWrap: true which makes the GridView to take minimum space and wrap the GridView with Center widget. Save this answer.

Which property of the GridView control you need to set to add and bind the columns manually?

GridView Data binding with AutoGenerateColumns = false You can manually define the column fields by setting the AutoGenerateColumns property to false and then creating a custom Columns collection.


2 Answers

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>
like image 70
Ritwik Avatar answered Oct 30 '22 01:10

Ritwik


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

like image 32
Pranay Rana Avatar answered Oct 30 '22 01:10

Pranay Rana