I have a grid with a bound field. I have set Item_style-wrap=true.
But still it is NOT wrapping the data for me. What could be the issue?
Grid code:
<asp:BoundField DataField="Reason"
HeaderText="Reason For Request"
ItemStyle-Wrap="true"
ItemStyle-Width="10%"
/>
Try this:
<asp:BoundField>
<HeaderStyle Wrap="true" />
<ItemStyle Wrap="true" />
</asp:BoundField>
Related
<asp:GridView ID="gv_Info" runat="server" Width="1240px" BorderWidth="1px"
CellPadding="4" BorderColor="Gray" AlternatingItemStyle-BackColor="#f6f6eb"
BackColor="#F3372A" AutoGenerateColumns="False" ShowFooter="false">
<AlternatingRowStyle BackColor="White" Wrap="false" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelectAsset" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="d" HeaderText="ATag">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="c" HeaderText="Description">
<HeaderStyle />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="a" HeaderText="AType">
<HeaderStyle />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="q" HeaderText="ID">
<HeaderStyle />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
</asp:GridView>
gv_InfoAssetsByParams.DataSource = ArrayAssets.ToList()
gv_InfoAssetsByParams.DataBind()
but when ArrayAssets is empty I want to make the gridview empty. SO I do this,
If ArrayAssets.Length > 0 Then
gv_Info.DataSource = ArrayAssets.ToList()
gv_Info.DataBind()
Else
gv_Info.DataSource = ArrayAssets.ToList()
gv_Info.DataBind()
End If
But it still appears even if i assign Nothing to the data source. How do I make it empty with headers?
ASP has a property called ShowHeader when empty. (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.showheaderwhenempty.aspx)
Set ShowHeaderWhenEmpty="false", that should work.
After looking at your code, you are repeating the same thing in your IF statement.
I tried to replicate your problem on my end, and indeed if the datasource is empty the grid is not visible. I think you should look at the properties of your gridview and go from there. As well, I recommend using a repeater for more control of the visibility and layout when displaying data.
I have a standard grid view, which contains a number of bounded fields and template fields, out of these I would like to make 4 columns invisible.
I know the css for this is visibility:hidden; but I do not know how to apply it to just these 4 columns, I have tried using the ControlStyle-CssClass property but it seems to apply the css to the whole table.
Is there a way to apply this css only to these 4 columns, also the plan is after I manage this is to write some Javascript for a button to switch the visibility on and off, so if you could please use some CSS/tags etc which can be easily changed client side it would be a huge plus.
A example:
<asp:GridView ID="gwFoo" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
Width="631px" OnRowDataBound="gwFoo_RowDataBound"
CssClass="customerDataTable" AllowSorting="True">
<Columns>
<asp:BoundField DataField="type" HeaderText="Type" SortExpression="type" />
<asp:TemplateField HeaderText="Number" SortExpression="id">
<ItemTemplate>
<asp:HyperLink ID="hlNumber" runat="server">[hlNumber]</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="product" HeaderText="Product" SortExpression="product" />
<asp:BoundField DataField="startDate" HeaderText="Start Date" SortExpression="startDate" />
<asp:BoundField DataField="endDate" HeaderText="End Date" SortExpression="endDate" />
<asp:BoundField DataField="isActive" HeaderText="Is Active ?" SortExpression="isActive" />
<asp:BoundField DataField="markedForActivation" HeaderText="Marked for Activation ?" SortExpression="markedForActivation" />
<asp:BoundField DataField="status" HeaderText="Status" SortExpression="status" />
<asp:TemplateField HeaderText="Parent Order" SortExpression="Foo">
<ItemTemplate>
<asp:HyperLink ID="hlFoo" runat="server">[hlFoo]</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Parent Document" SortExpression="Foo">
<ItemTemplate>
<asp:HyperLink ID="hlFoo" runat="server">[hlFoo]</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="createdDate" HeaderText="Created Date" <itemstyle Visible="false"></itemstyle> SortExpression="createdDate" />
<asp:BoundField DataField="createdBy" HeaderText="Created By" SortExpression="createdBy" />
<asp:BoundField DataField="lastUpdated" HeaderText="Last Updated" SortExpression="lastUpdated" />
<asp:BoundField DataField="lastUpdatedBy" HeaderText="Last Updated By" SortExpression="lastUpdatedBy" />
</Columns>
</asp:GridView>
give the columns a class and set the class css to visiblity:hidden;
Using Visible="false" will works
ie
<asp:BoundField Visible="false" DataField="status" HeaderText="Status" SortExpression="status" />
I solved the problem, in a way in which I can also switch the invissibility on and off from a button.
First I refactored the bounded fields I wanted to hide in this manner:
<asp:BoundField DataField="createdBy" HeaderText="Created By" SortExpression="createdBy" >
<ItemStyle CssClass="fooClass"></ItemStyle>
</asp:BoundField>
The class fooClass is a empty css class, I used it only so that all the <td> </td> elements which are generated by the bounded field share a common class, thus allowing the jquery script I wrote bellow to hide or show them.
<script> $(".fooClass").hide(); </script>
// or
<script> $(".fooClass").show(); </script>
i use this code .. but when the hyperlinks are longer then field size the gridview expands verticaly. i want the link below as like a paragraph . give me a solution
<asp:gridview id="titlesGrid" runat="server"
datasourceid="titles"
width=90% cellpadding=5 font-size="8pt"
autogeneratecolumns=false
headerstyle-backcolor="maroon"
headerstyle-forecolor="khaki"
headerstyle-font-bold
rowstyle-verticalalign="top">
<columns>
<asp:hyperlinkfield headertext="Title"
datatextfield="title"
datanavigateurlformatstring="title_details.aspx?titleid={0}"
datanavigateurlfields="title_id" />
<asp:boundfield headertext="Title ID"
datafield="title_id" />
<asp:boundfield headertext="Category"
datafield="type" />
<asp:boundfield headertext="Pub ID"
datafield="pub_id" />
<asp:boundfield headertext="Price"
datafield="price"
htmlencode=false
dataformatstring="{0:n2}"
itemstyle-horizontalalign="right" />
</columns>
</asp:gridview>
Have you tried using <ItemStyle Wrap="True" /> for <asp:hyperlinkfield /> ?
<asp:BoundField DataField="ComputerModel" HeaderText="ComputerModel"
SortExpression="ComputerModel"
ItemStyle-Width="50px"/>
<asp:CheckBoxField DataField="Lease" HeaderText="Lease"
SortExpression="Lease" />
<asp:BoundField DataField="SerialNumber" HeaderText="SerialNumber"
SortExpression="SerialNumber" />
<asp:BoundField DataField="LeasedTagNum" HeaderText="LeasedTagNum"
SortExpression="LeasedTagNum" />
<asp:BoundField DataField="MonitorType" HeaderText="MonitorType"
SortExpression="MonitorType" />
<asp:BoundField DataField="MonitorCount" HeaderText="MonitorCount"
SortExpression="MonitorCount" />
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
Try something like this:
<asp:BoundField DataField="ComputerModel" ItemStyle-Width="50px"/>
where 50px is the width you need.
Try this:
<asp:BoundField DataField="ComputerModel" HeaderText="ComputerModel"
SortExpression="ComputerModel"
HeaderStyle-Width="50px" >
</asp:BoundField>
Can we see all the HTML for the control? I'm curious to see the markup for the entire control so I don't make any assumptions.
Per MSDN try
<asp:boundfield
sortexpression="LastName"
datafield="LastName"
headertext="LastName">
<itemstyle width="50px">
</itemstyle>
</asp:boundfield>
I would like to see what you have thus far and maybe I can be more helpful. Also is there any CSS class that may be setting the item width?
How do you control the column width in a gridview control in ASP.NET 2.0?
You can use the HeaderStyle-Width, ItemStyle-Width or FooterStyle-Width properties. These can be applied to all the columns or per-column basis.
<asp:GridView ID="GridView1" runat="server">
<HeaderStyle Width="10%" />
<RowStyle Width="10%" />
<FooterStyle Width="10%" />
<Columns>
<asp:BoundField HeaderText="Name" DataField="LastName"
HeaderStyle-Width="10%" ItemStyle-Width="10%"
FooterStyle-Width="10%" />
</Columns>
</asp:GridView>
I do it using the header style for the column:
<asp:BoundField HeaderText="Name" DataField="LastName">
<HeaderStyle Width="20em" />
</asp:BoundField>
Here's the C# code to do it programatically:
columnName.ItemStyle.Width = Unit.Percentage(someDouble);
Gridview.Columns[1].ItemStyle.Width = 100;
This will set the with in pixel.