Cannot set row height on a gridview control - asp.net

Here is my ASP:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateEditButton="true"
DataSourceID="AccessDataSource1"
AutoGenerateColumns="False" DataKeyNames="ID"
RowStyle-CssClass="editPhotoGridFormat"
AlternatingRowStyle-CssClass="editPhotoGridFormat"
AlternatingRowStyle-BackColor="Gray"
RowStyle-Height="400px"
RowStyle-VerticalAlign="Top">
<RowStyle Height="400px" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="BlogTitle" HeaderText="BlogTitle"
SortExpression="BlogTitle" />
<asp:ImageField DataImageUrlField="Image" HeaderText="Image"
DataImageUrlFormatString="~/PlaceImages/{0}" ControlStyle-CssClass="editPhotoGridFormat"
AlternateText="Something went wrong"
NullDisplayText="No picture on file" />
<asp:BoundField DataField="PicText" HeaderText="PicText" />
<asp:BoundField DataField="TravelDate" HeaderText="TravelDate" SortExpression="TravelDate" />
<asp:BoundField DataField="BeginText" HeaderText="BeginText" ItemStyle-Height="10px" />
<asp:BoundField DataField="Caption" HeaderText="Caption" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
<asp:BoundField DataField="EndText" HeaderText="EndText" />
</Columns>
</asp:GridView>
Here's my CSS:
.editPhotoGridFormat
{
width: 220px;
height: 180px;
}
It seems like no matter where I set height, it doesn't want to change the height of my rows. You can see that I have set the height in many places in my code, and I've tried using each one individually. Any ideas folks? All the posts on gridview row height here seem to be for Android, lol.

Try this
<asp:GridView ID="GridView1"> <rowstyle Height="20px" /></asp:GridView>
OR
Mention the height value for RowStyle(& AlternateRowStyle) in your HTML source
You can do that same in code-behind
GridView1.RowStyle.Height = 50;
But my suggestion is use CSS(Best way)
.RowStyle {
height: 50px;
}
.AlternateRowStyle {
height: 50px;
}
HTML Source
<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
RowStyle-CssClass="RowStyle"
AlternatingRowStyle-CssClass="AlternateRowStyle">
</asp:gridview>

Have you tried to set the row height in your css?
Set this style in the CssClass properties for the RowStyle and AlternateRowStyle styles of your GridView:
.smallRow
{
height: 150px;
}

Related

Forcing Gridview Header font bold to false in ASP.NET

I am having a problem in forcing gridview header to "unbold". I tried using the Gridview parameter for header font style but it doesn't really work. Unfortunately, all other methods I tried did not work.
Using CSS Class
.headercell
{
font-weight: normal;
font-size: 12px;
font-family: "Franklin Gothic Book"
}
Programmatically using Row Data Bound
If e.Row.RowType = DataControlRowType.Header Then
For i = 0 To GridView1.Columns.Count - 1
GridView1.Columns(i).HeaderStyle.Font.Bold = False
Next
End If
What would be the most efficient way to set the gridview header to unbold?
UPDATE (ASPX CODE):
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#333333" BorderStyle="Solid" BorderWidth="2px"
CellPadding="3" Font-Bold="false" Font-Overline="False"
Font-Size="Small" Font-Underline="False" HtmlEncode="false">
<RowStyle ForeColor="#000066" Height="23px" HorizontalAlign="Center"
VerticalAlign="Middle" />
<FooterStyle BackColor="White" ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066"
HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#002851" Font-Bold="False"
CssClass="headercell" ForeColor="White" HorizontalAlign="Left"
VerticalAlign="Middle" />
<Columns>
<asp:TemplateField HeaderText="STATUS" ShowHeader="False"
Visible="True">
<ItemTemplate>
<asp:Button ID="Btn1" runat="server" CommandArgument='<%#
DataBinder.Eval(Container, "RowIndex") %>'
CommandName="Btn1_cmd">
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You can use HeaderStyle-Font-Bold on your <asp:BoundField /> So just set it to false as following
HeaderStyle-Font-Bold="false"
Add a CssClass namely "gvstyling" to your gridview
Write a css just like this...
.gvstyling th
{
font-size: 12px;
font-weight: normal;
}
Try below :
th {
font-weight: normal;
}
This is the cssclass I added to the Gridview:
.Grid, .Grid th, .Grid td
{
border-color: #CCCCCC;
font-family: Franklin Gothic Book;
font-size: 12px;
font-weight: normal;
}
In the source code, I just added CssClass="Grid" to the Gridview (not in header cssclass).

DataGrid columns collection is not updating column widths programmatically or through grids properties

have searched all day for solution to vb.net web project, 3.5 framework (VS 2008) which uses DataGrid (not gridview) to set consistent widths for all 17 columns in my grid. The grid is overflowing past the div area and the "Note" column particularly is very wide with very little text in it. For this particular column I've tried both allowing wrapping and nowrap and but the width never changes. I've set the width of columns in the grid properties column collection with no change. Now I am setting the widths programmatically like so but with minimal effects. The Note column is still quite wide.
Ideally what I would like is to fix column sizes (not auto grow or shrink) and have text that is too large to fit to be cut off. I haven't designated an overall grid width. Is that why the grid is misbehaving?
vb.net:
DataGrid1.Columns(14).HeaderStyle.Width = Unit.Pixel(25) 'LightDuty
DataGrid1.Columns(14).HeaderStyle.Wrap = True
'
DataGrid1.Columns(15).HeaderStyle.Width = Unit.Pixel(150) 'Note
DataGrid1.Columns(15).HeaderStyle.Wrap = True
css:
#grid
{
float:left;
width:100%;
/*border: 1px solid blue;*/
margin: 10px 10px 0px 10px;
padding:10px 10px 1px 10px;
text-align:center;
}
aspx: (just a portion of the top of the grid)
<div id="grid">
<asp:datagrid id="DataGrid1" runat="server"
Font-Names="Tahoma"
Font-Size="Small"
ShowFooter="True"
DataMember="vwSomeDataSetTable"
AutoGenerateColumns="False"
AllowSorting="True"
PageSize="25"
OnPageIndexChanged="DataGrid1_Paging" >
<FooterStyle HorizontalAlign="Right"></FooterStyle>
<SelectedItemStyle HorizontalAlign="Left" />
<PagerStyle HorizontalAlign="Left" Mode="NumericPages"
Position="TopAndBottom" />
<AlternatingItemStyle BackColor="#EBF5FF"></AlternatingItemStyle>
<headerStyle Font-Bold="True" ></headerStyle>
<Columns>
<asp:BoundColumn DataField="name" SortExpression="name" HeaderText="Employee">
<headerStyle HorizontalAlign="Center" Font-Bold="False" Font-Italic="False"
Font-Overline="False" Font-Size="Small" Font-Strikeout="False"
Font-Underline="False" Wrap="False"> </headerStyle>
<ItemStyle Wrap="False" Font-Bold="False" Font-Italic="False"
Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
HorizontalAlign="Left"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="LD" SortExpression="LD"
HeaderText="LD">
<headerStyle HorizontalAlign="Center" Font-Bold="False" Font-Italic="False"
Font-Overline="False" Font-Size="Small" Font-Strikeout="False"
Font-Underline="False" Wrap="False" />
<ItemStyle Font-Names="Webdings" Wrap="false" HorizontalAlign="Left"
Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False"/>
</asp:BoundColumn>
<asp:BoundColumn DataField="Note" SortExpression="note" HeaderText="Note">
<headerStyle HorizontalAlign="Center" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Wrap="False"></headerStyle>
<ItemStyle Wrap="False" Font-Bold="False" Font-Italic="False"
Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
HorizontalAlign="Left"></ItemStyle>
</asp:BoundColumn>
Naturally as soon as I ask for help, I come to a solution on my own!
UPDATE: I removed everywhere I had set to allow wrapping in the grid columns collection properties for each headerstyle and itemstyle of every column as I realized some were set to wrap, some were not, creating inconsistencies with what I was attempting to set programmatically and once I did that, the columns started shrinking to a more usable size. I still have a way to go, but it's getting better.

Center column of GridView Overriding GridView CssClass

I have a GridView using a few css classes, that is okay.
The problem is that applying individual Css classes to the boundfield of the gridview is not being applied..
Here is My grid view:
<asp:GridView ID="gvwExample" runat="server" CssClass="table table-bordered table-condensed epalist gridtextcenter" EmptyDataText="The search didn't return any records" ShowHeaderWhenEmpty="true" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowDataBound="gvwExample_RowDataBound" >
<columns>
<asp:BoundField DataField="NB" ItemStyle-CssClass="textleft" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="6%" HeaderText="NB" />
<asp:BoundField DataField="Name" ItemStyle-Width="19%" HeaderText="Name" />
<asp:BoundField DataField="CLevel" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="6%" HeaderText="CLevel" />
<asp:BoundField DataField="CC Host" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="7%" HeaderText="CC Host" />
<asp:BoundField DataField="System" ItemStyle-Width="15%" HeaderText="System" />
<asp:BoundField DataField="Object Type" ItemStyle-Width="12%" HeaderText="Object Type" />
<asp:BoundField DataField="Object ID" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="8%" HeaderText="Object ID" />
<asp:BoundField DataField="Object Description" ItemStyle-Width="17%" HeaderText="Object Description" />
<asp:BoundField DataField="Excl Mngr" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="9%" HeaderText="Excl Mngr" />
</columns>
</asp:GridView>
Here is my CssClass of the first column "NB":
.textleft{
text-align:left;
}
.gridtextcenter td, .gridtextcenter th{
text-align:center;
}
So the main thing is:
the class "gridtextcenter" will center all the text of all my td, but the first column use the css class "textleft" that should place the text not centered, why is not working??
Thanks alot in advance ;)
Because .gridtextcenter td has more specificity than .textleft
write your css in this way
.gridtextcenter .textleft{
text-align:left;
}
.gridtextcenter td, .gridtextcenter th{
text-align:center;
}
How Specificity works :
1 = for all type of tags like <p>, <a>
10 = for class like .className
100 = for id like #idName

IE8 removes background-color of header row of Asp:Gridview

I am using Asp.net 4.0 GridView control to display data from database. I have applied the inbuilt theme to GridView.
<asp:GridView ID="gv" runat="server" CellPadding="4" EmptyDataText="No records found."
ForeColor="#333333" OnRowCommand="gv_RowCommand" Width="99%" OnPageIndexChanging="gv_PageIndexChanged"
PageSize="50" AllowPaging="True" GridLines="None" AutoGenerateColumns="true">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle CssClass="GridHeader" BackColor="#1C5E55" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" /></asp:GridView>
I tried setting the CSS forcefully in my Master page
.GridHeader { background-color:#1C5E55 !important;}
But I am still missing the background-color.
I can see the backgroundcolor applied to grid (for less-than 1 sec) while the page loading the js/css content
NOTE: I already tried clearing cache of IE, ctrl + F5, shift + reload etc.
Here is sample page of my issue.
http://vd2.weenggs.com/Items.aspx
email: test#test.com
pass: test
.PACP-box:before, .PACP-box:after, .PACP-box-body:after, .PACP-box-body:before
{
background-repeat: no-repeat;
bottom: 0;
content: " ";
line-height: 0;
position: absolute;
top: 0;
}
I find the above CSS block causes the style render/override issue.I can not remove this block because it causes layout break.
Can anyone have the alternate CSS for the above block. ?
​
Thanks
I see #1C5E55 in the header. I don't see any GridHeader class defined in HTML. BackColor defined in HeaderStyle is coded throw tr's style attribute. As you mentioned, you color is overridden by ecmascript code. You can easily check this by disabling ecmascript. Then you will know if the problem is in CSS or scripting.
Give BackColor="the color you want" it works for All browsers. but you wont be able to give gradient to the header

gridview multiple check box column

Work on asp.net vs05. I have three type of value Like:IsDesign,IsPrinting,IsInstall they are bit type. To represent this bits values on my gridview I use three checkbox columns, GridView control with three header checkbox and checkbox for each individual record. When you click the header check all checkboxes when the header checkbox is checked it highlights all the rows and checks the checkboxes in all rows, and when unchecked it restores back the original color of the row and unchecks the checkboxes.
To complete this task, want to use the client side script.
<asp:GridView ID="gvSearch" runat="server" AutoGenerateColumns="False" DataKeyNames="JobID" Width="880px" CellPadding="5" ForeColor="#333333" GridLines="None" AllowPaging="True" HorizontalAlign="Center" CellSpacing="1" PageSize="5" ShowFooter="True" Height="278px" OnPageIndexChanging="gvSearch_PageIndexChanging" OnRowDataBound="gvSearch_RowDataBound">
<Columns>
<asp:CheckBoxField HeaderText="IsDesign" />
<asp:CheckBoxField HeaderText="IsPrinting" />
<asp:TemplateField HeaderText="IsInstall">
<EditItemTemplate>
<asp:CheckBox ID="ckbIsDelivered" runat="server" Checked='<%# Bind("IsDelivered") %>' Text="IsDelivered" />
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" />
</FooterTemplate>
<ItemTemplate>
<asp:CheckBox ID="ckbIsDelivered" runat="server" onclick = "Check_Click(this)" Checked='<%# Bind("IsDelivered") %>' />
</ItemTemplate>
<HeaderTemplate>
<br />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 21px">
<input id="chkAll" name="chkAll" onclick = "checkAll(this);" type="checkbox" />
</td>
<td style="width: 70px">
<asp:Label ID="Label14" runat="server" Text="IsDelivered" />
</td>
</tr>
</table>
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="JobID " SortExpression="JobID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("JobID") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblJobID" runat="server" Text='<%# Bind("JobID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="JobNo" HeaderText="JobNo " SortExpression="JobNo" />
<asp:BoundField DataField="ClientName" HeaderText="ClientName " SortExpression="ClientName" />
<asp:BoundField DataField="MediaName" HeaderText="MediaName " SortExpression="MediaName" />
<asp:BoundField DataField="BrandName" HeaderText="BrandName " SortExpression="BrandName" />
<asp:BoundField DataField="JobTypeDesc" HeaderText="JobTypeDesc " SortExpression="JobTypeDesc" />
<asp:BoundField DataField="JobDesc" HeaderText="JobDesc " SortExpression="JobDesc" />
<asp:BoundField DataField="OutletNameEnglish" HeaderText="OutletNameEnglish " SortExpression="OutletNameEnglish" />
<asp:BoundField DataField="OutletAddressEnglish" HeaderText="OutletAddressEnglish " SortExpression="OutletAddressEnglish" />
<asp:BoundField DataField="Length" HeaderText="Length " SortExpression="Length" />
<asp:BoundField DataField="Height" HeaderText="Height " SortExpression="Height" />
<asp:BoundField DataField="Sft" HeaderText="Sft " SortExpression="Sft" />
<asp:BoundField DataField="DeliveryTargetDate" HeaderText="DeliveryTargetDate " SortExpression="DeliveryTargetDate" DataFormatString="{0:dd MMM yyyy}" />
<asp:BoundField DataField="JobPriorityID" HeaderText="JobPriorityID " SortExpression="JobPriorityID" />
<asp:BoundField DataField="Remarks" HeaderText="Remarks " SortExpression="Remarks" />
<asp:CheckBoxField DataField="Status" HeaderText="Status " SortExpression="Status" />
<asp:CheckBoxField DataField="IsActive" HeaderText="IsActive " SortExpression="IsActive" />
</Columns>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" Height="50px" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Height="20px" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" BorderWidth="1px" Height="20px" />
<EditRowStyle BackColor="#999999" Height="40px" Width="100px" />
This will become much easier if you use CSS rules for your styling instead of inline styles like you currently have. To do this, change your row style tags to only specify CSS classes, not specific styles, like this:
<asp:GridView ID="gvSearch" runat="server" CssClass="gridView">
<%-- ... Your other markup here ... --%>
<AlternatingRowStyle CssClass="altRow" />
<RowStyle CssClass="row" />
<FooterStyle CssClass="footer" />
<PagerStyle CssClass="pager" />
<SelectedRowStyle CssClass="selectedRow" />
<HeaderStyle CssClass="headerRow" />
<EditRowStyle CssClass="editingRow" />
</asp:GridView>
Then you can apply the same styles you originally had inline in your markup using a style sheet like this (all of the CSS rules are exactly the same as your original inline styles):
.gridView { width: 880px; padding: 5px; color: #333; text-align: center;
height: 278px; border-collapse:separate;border-spacing: 1px;}
.altRow { background: #fff; color: #284775 }
.row { background: #f7f6f3; color: #333; height: 50px }
.footer { background: #5d7b9d; font-weight: bold; color: #fff; height: 20px }
.pager { background: #284775; color: #fff; text-align: center; }
.selectedRow { background: #e2ded6; font-weight: bold; color: #333 }
.headerRow { background: #5d7b9d; font-weight: bold; color: #333;
text-align: center; border: 1px solid #000; height: 20px }
.editingRow { background: #999; height: 40px; width: 100px }
Once you've got your CSS established, the next thing to do is handle clicking the header check boxes. To do this, you must use a JavaScript framework like jQuery, Dojo, YUI, MooTools or Prototype. Doing it without one would take me all day to write out and explain properly, and even then it may not even work across all browsers. I'll show you how to do what I think you're looking for using jQuery, since that is what I'm most comfortable with, however any JavaScript framework can accomplish the same thing.
In your header template, you won't need anything except an ID on your <input /> tag, which you already have. You should remove the onclick attribute you already have, since you won't need it. Make sure you're using the CSS rules I defined above, as the code I'm going to write relies on it being there.
First, subscribe to the click event of the header checkbox. When the checkbox is clicked, this code finds the column the checkbox exists in and then goes through every row in the table and clicks the checkbox it finds in that column.
$(document).ready(function() {
$("#chkAll").click(function(){
// First find the column index of the clicked checkbox
// If you know your column order won't change, this
// can be done with less code by just hard-coding
// the "colIndex" variable to the zero-based column number
var $this = $(this);
var clickedColumn = $this.closest(".headerRow > th");
var headerRow = $this.closest(".headerRow");
var colIndex = headerRow.children().index(clickedColumn);
// Next, traverse through the table, checking or
// unchecking each checkbox in the specified column index
var table = $this.closest("table.gridView");
if (this.checked) {
table.find("tr.altRow, tr.row").each(function() {
var $this = $(this);
// Finding the checkbox in the correct column
// involves finding the correct column and then
// getting the checkbox inside it. This is easy
// with jQuery
var checkbox = $this.children()
.eq(colIndex)
.children("input:checkbox");
checkbox.attr("checked", true);
$this.addClass("selectedRow");
});
} else {
table.find("tr.altRow, tr.row").each(function() {
var $this = $(this);
// Finding the checkbox in the correct column
// involves finding the correct column and then
// getting the checkbox inside it. This is easy
// with jQuery
var checkbox = $this.children()
.eq(colIndex)
.children("input:checkbox");
checkbox.attr("checked", false);
$this.removeClass("selectedRow");
});
}
});
});
A working demo of this can be found at: http://jsbin.com/alafo

Resources