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;
}
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>
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
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;
}
on your div text-align: center
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;
}
.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>
Related
Q1. I have a hyperlink field in a grid view as below :
<asp:HyperLinkField Text="Analyze" />
I want it to be underlined at all times and not only when I hover. How do I do this ?
Q2. I want the header texts of the gridView to be center alligned.
I tried: HeaderStyle-HorizontalAlign="Left" but it doesn't work.
I also tried making a css class with :
<style type="text/css">
.header-center{
text-align:center;}
</style>
but this also doesn't work.
I am basically trying to center the header text,nothing fancy,but it is not happening.
You have to replace your code in BodyContent with the below.
Note: you can add your own colors to the grid
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<style type="text/css">
#MainContent_GridView2 tbody tr th {
text-align: center;
background: #808080;
height: 40px;
}
#MainContent_GridView2 tbody tr {
height: 20px;
background-color: #CCC;
}
#MainContent_GridView2 tbody tr:hover {
background-color: #808080;
}
#MainContent_GridView2 tbody tr td {
text-align: center;
height: 30px;
}
.linkfield {
text-decoration: underline;
text-align: center;
}
</style>
<asp:GridView ID="GridView2"
runat="server"
AutoGenerateColumns="False"
AllowPaging="True"
AllowSorting="True"
PageSize="25"
Height="800px"
Width="1200px"
OnPageIndexChanging="GridView2_PageIndexChanging">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="runId" DataTextField="runId" HeaderText="RunID" DataNavigateUrlFormatString="RunAnalysis.aspx?runId={0}" ItemStyle-Width="10%">
<ItemStyle Width="10%" CssClass="linkfield"></ItemStyle>
</asp:HyperLinkField>
<asp:BoundField DataField="prodDate" HeaderText="Date" DataFormatString="{0:MM/dd/yy}" ItemStyle-Width="10%">
<ItemStyle Width="10%"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="buildNumber" HeaderText="Build Number" ItemStyle-Width="10%">
<ItemStyle Width="10%"></ItemStyle>
</asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="PercentAnalysed" DataTextField="PercentAnalysed" HeaderText="Percent Analysed" ItemStyle-Width="10%">
<ItemStyle Width="10%"></ItemStyle>
</asp:HyperLinkField>
</Columns>
<PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next" PreviousPageText="Previous" />
</asp:GridView>
</asp:Content>
Hope this helps.
New to asp.net and I am trying to center the hover portion of my menu control but for the life of me I cannot figure it out.
Here is my code:
<aside>
<nav>
<asp:Menu ID="Menu" runat="server" DataSourceID="SiteMapDataSource1" DynamicEnableDefaultPopOutImage="False" Orientation="Horizontal"
RenderingMode="Table" backcolor="#CB4154" ForeColor="white" Font-Bold="True" >
<StaticMenuItemStyle HorizontalPadding="8px" VerticalPadding="2px" />
<StaticMenuStyle height="25px" Width="800px" />
<StaticSelectedStyle HorizontalPadding="8px" VerticalPadding="2px" />
<StaticHoverStyle Font-Bold="True" height="75%" width="50%" backcolor="#00B7EB" ForeColor="White" CssClass="StaticHoverStyle"/>
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
</nav>
</aside>
And the CSS:
#Menu {
text-align: center;
margin-right:auto;
margin-left: auto;
}
.StaticHoverStyle {
text-align: center;
}
Any input on what I am doing wrong would be appreciated.
make it absolute and add right and left tags
#Menu {
position:absolute;
text-align: center;
margin-right:auto;
margin-left: auto;
right:0px;
left:0px; }
}
.StaticHoverStyle {
text-align: center;
}
i just had a quick look at mine (been a while) and it looks like i put text-align in a wrapping div. what happens it you move your text-align to the nav element? (move the data source out, for clarity.)
I am using the Ajax Modal Popup Extender to display a panel as a modal popup. I've applied a CSS class to the panel and everything displays fine. However, when I add the BackgroundCssClass property to my popup extender, the border on my panel does not show up. The modal background displays properly and everything else in the panel remains the same, but I can't get the border to display. What might be causing this?
**CSS**
.PopupPanel
{
width: 75%;
height: 55%;
text-align: center;
padding: 5px;
overflow: auto;
border-style: solid;
border-width: 8px;
border-color: #0055A5;
background-color: White;
}
.ModalBackground
{
background-color: rgba(170,170,174,0.5);
}
**ASPX**
<asp:Panel ID="InputPanel" runat="server" CssClass="PopupPanel">
<asp:Label ID="HeaderLabel" runat="server"
Text="[text here]"
Font-Size="Large"></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="85%"
Height="65%" Wrap="False"></asp:TextBox>
<br />
<asp:Button ID="okButton" runat="server" Text="Submit"
CssClass="genericButton" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel"
CssClass="genericButton" />
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
PopupControlID="InputPanel" TargetControlID="PasteButton"
BackgroundCssClass="ModalBackground" PopupDragHandleControlID="HeaderLabel">
</ajaxToolkit:ModalPopupExtender>
I have a two column layout page with a Validation Summary (VS) control above the 2 columns. The VS is centered in the container above the columns, which is what I want, but I also want the different bullet points to be vertically aligned, if possible. I have tried several things, including placing the VS inside a div (inside the container div that is center aligned) with text-align:left;, but that moves the entire div to the side of the container. I have also tried making the div text-align:center; and the VS text-align:left;, but that also moves the entire block all the way to the left. I've also tried the same thing with a table, but no luck.
This is in Firefox by the way. I haven't tested in other browsers, but it needs to work in FF.
Here is pic to show the messed up vertical alignment:
And here is the code for my VS control, without my alignment attempts (if more code is needed, let me know):
<div id="container">
<asp:Label ID="lblStatus" runat="server" ForeColor="Red"></asp:Label>
<asp:ValidationSummary ID="VS1" runat="server" CssClass="validator" ValidationGroup="theform" />
<div id="leftCol">
Could somebody help me vertically align those bullet points in the center of the page?
Since bullet points are part of the list items I don't think you will be able to align them. Why not try something like having a top column with 3 divs and place your validationsummary control in the middle one. Try this
HTML Code
<div id="container" class="container">
<div id="top" class="top">
<div id="topLeft" class="topLeft">
</div>
<div id="topMiddle" class="topMiddle">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</div>
<div id="topRight" class="topRight">
</div>
</div>
<div id="bottom" class="bottom">
<div id="bottomLeft" class="bottomLeft">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="input value" ControlToValidate="TextBox1" Text="*"></asp:RequiredFieldValidator><br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Need come input for this" ControlToValidate="TextBox2" Text="*"></asp:RequiredFieldValidator><br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
<div id="bottomRight" class="bottomRight">
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="please input text" ControlToValidate="TextBox3" Text="*"></asp:RequiredFieldValidator><br />
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Where is the text?" ControlToValidate="TextBox4" Text="*"></asp:RequiredFieldValidator><br />
<asp:Button ID="Button2" runat="server" Text="Button" />
</div>
</div>
</div>
CSS
.container
{
display: block;
width:800px;
margin:0px;
padding:0px;
}
.top
{
display:inline-block;
width:800px;
}
.bottom
{
display:inline-block;
}
.topMiddle
{
display:inline;
background-color:Yellow;
float:left;
width:300px;
}
.topLeft
{
display:inline;
float:left;
width:250px;
}
.topRight
{
display:inline;
float:left;
width:250px;
}
.bottomLeft
{
display:inline;
width:400px;
float:left;
background-color:Orange;
}
.bottomRight
{
display:inline;
width:400px;
float:left;
background-color:Lime;
}
Hey you may define your parent text-align left center right
according to your design
Try using this one....
<style>
.validator ul li { text-align:left; }
</style>
Edit
Set padding left or margin left to ul as you want...
.validator ul { padding-left: 100px; }
I'm looking for a straight forward css solution that will force labels to top align with their controls in asp. So for example:
<asp:Label runat="server" AssociatedControlID="cboBox" Text="Control Label" />
<asp:DropDownList runat="server" ID="cboBox" />
Would appear something like:
Control Label
[[[[[]]]]]]]]]]]]V
Any ideas?
Wrap them both in a span or div:
<span class="field">
<asp:Label runat="server" AssociatedControlID="cboBox" Text="Control Label" />
<asp:DropDownList runat="server" ID="cboBox" />
</span>
Then:
.field label,
.field select
{
display: inline-block;
vertical-align: top;
/* achieves same as inline-block for IE7 */
*display: inline;
*zoom: 1;
}
You can try putting them in a container, and apply specific styling for spans within that container. The example below might need a little tweaking, but it should point you in the right direction:
div.container span {
display: table-cell;
vertical-align: top;
}
div.container input {
display: table-cell;
vertical-align:middle;
}
And then on the page:
<div class="container">
<asp:Label runat="server" AssociatedControlID="cboBox" Text="Control Label" />
<asp:DropDownList runat="server" ID="cboBox" />
</div>