I'm tying to skin ASP.NET GridView CommandField.
Everything si working fine, just when I move CommandField property declarations from page to skin file, the whole commandField properties are ignored. here is my skin file:
<asp:GridView
AllowPaging="true"
AllowSorting="false"
AutoGenerateEditButton="false"
AutoGenerateDeleteButton="false"
AutoGenerateSelectButton="false"
AutoGenerateColumns="false"
GridLines="None"
PageSize="20"
ShowFooter="false"
ShowHeader="true"
runat="server">
<Columns>
<asp:CommandField
ButtonType="Image"
ControlStyle-Width="25"
EditImageUrl="Images/Icons/pencil.png"
DeleteImageUrl="Images/Icons/cross.png"
/>
</Columns>
</asp:GridView>
In web.config I apply only StyleSheetTheme. Do I miss something?
Thanks
This can be achieved by using StyleSheetTheme and NOT Theme.
Following is the control style defined in a .skin file
<asp:GridView runat="server" Font-Names="verdana,arial,sans serif" AllowSorting="True" AllowPaging="True" AutoGenerateColumns="False" Width="95%">
<Columns>
<asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/Buttons/16x16/Cancel.gif"
EditImageUrl="~/Images/Buttons/16x16/Edit.gif" ShowEditButton="True" InsertImageUrl="~/Images/Buttons/16x16/New.gif" UpdateImageUrl="~/Images/Buttons/16x16/Update.gif" />
<asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/Buttons/16x16/Delete.gif"
ShowDeleteButton="True" />
</Columns>
<RowStyle Font-Size="Smaller" ForeColor="Black" />
<PagerStyle Font-Size="Smaller" ForeColor="Black" />
<SelectedRowStyle BackColor="Yellow" />
<HeaderStyle BackColor="#2D5C3D" Font-Size="Smaller" ForeColor="White" HorizontalAlign="left" />
<FooterStyle BackColor="#2D5C3D" />
<EditRowStyle BackColor="#2D5C3D" />
<AlternatingRowStyle BackColor="#ECE9D8" />
The web.config file defines the StyleSheetTheme as site level
<pages styleSheetTheme="Green" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
The .aspx page containing the GridView control
<asp:GridView ID="gvUser" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" onpageindexchanged="gvUser_PageIndexChanged"
onpageindexchanging="gvUser_PageIndexChanging"
onrowcancelingedit="gvUser_RowCancelingEdit" onrowdeleting="gvUser_RowDeleting"
onrowediting="gvUser_RowEditing" onrowupdating="gvUser_RowUpdating"
onselectedindexchanging="gvUser_SelectedIndexChanging" onsorted="gvUser_Sorted"
onsorting="gvUser_Sorting">
<Columns>
<asp:BoundField DataField="Id" HeaderText="User Id" >
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" />
</asp:BoundField>
</Columns>
</asp:GridView>
For detail please refer to the following
http://weblogs.asp.net/vimodi/ThemesFaqs
http://weblogs.asp.net/vimodi/WhatIs-StyleSheetTheme
Hope this helps!
I get:
Content of literal
<asp:CommandField
ButtonType="Image"
ShowDeleteButton="true"
ItemStyle-Width="25"
DeleteImageUrl="~/App_Themes/SimplaAdmin/Images/Icons/cross.png"
/>
is not allowed within a skin file.
If you want to use a Fontawesome icon, you can change it like that:
<asp:CommandField ButtonType="Link" ShowEditButton="true"
EditText="<i class='fas fa-edit'></i>" />
for Delete use:
DeleteText="<i class='fas fa-trash-alt'></i>"
for Canel use:
CancelText="<i class='fas fa-window-close'></i>"
for Update use:
UpdateText="<i class='fas fa-sync'></i>"
What happens if you move the CommandField tag outside of the GridView tag?
i.e.:
<asp:GridView
AllowPaging="true"
AllowSorting="false"
AutoGenerateEditButton="false"
AutoGenerateDeleteButton="false"
AutoGenerateSelectButton="false"
AutoGenerateColumns="false"
GridLines="None"
PageSize="20"
ShowFooter="false"
ShowHeader="true"
runat="server">
</asp:GridView>
<asp:CommandField
ButtonType="Image"
ControlStyle-Width="25"
EditImageUrl="Images/Icons/pencil.png"
DeleteImageUrl="Images/Icons/cross.png"
/>
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 grid on my aspx page.I have set its font property to small..
On page load it is all okay..
but once I perform some action like a delete activity given in the grid itself..and the grid is bound again by recalling the method to bind grid..
the grid seems to be bigger with big fonts.
What could be the trouble?
<asp:GridView ID="grdSMEList" runat="server" Width="100%" BorderWidth="1px" BorderStyle="Solid"
Font-Size="Small" AutoGenerateColumns="False" BorderColor="#ffcc00" RowStyle-BorderColor="#ffcc00"
AllowPaging="true" PageSize="10" OnPageIndexChanging="GrdDynamic_PageIndexChanging"
DataKeyNames="Resource Personnel No" OnRowCommand="GrdDynamic_RowCommand" RowStyle-BorderStyle="Solid"
RowStyle-BorderWidth="1px" GridLines="Both" Height="104px">
<PagerSettings NextPageText=">>" PageButtonCount="5" PreviousPageText="<<"
FirstPageText="" LastPageText="" Mode="Numeric" />
<PagerStyle HorizontalAlign="Right" Font-Size="Medium" />
<Columns>
<asp:BoundField DataField="Resource Personnel No" HeaderText="Resource Personnel No" ItemStyle-Width="100px" />
<asp:BoundField DataField="RES Name" HeaderText="ResourceName" ItemStyle-Width="100px" />
<asp:TemplateField HeaderText="Deactivate" >
<ItemTemplate>
<div style="text-align:center;">
<asp:LinkButton ID="linkDeactivate" CommandName="cmdDeactivate" OnRowCommand="GrdDynamic_RowCommand"
CommandArgument='<%# Eval("Resource Personnel No") %>' OnClientClick="return confirm('Are you sure you want to Deactivate?');"
runat="server">Deactivate</asp:LinkButton>
</div>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="2%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Did you try specifying the font color in ItemTemplate ? Its worth a try.
I have a gridview. Is it possible to modify the gridview so that I can have multiple rows in the column headers? For example, the following code generates the table in the picture below.
<asp:GridView ID="productsGridView" Runat="server" DataSourceID="productDataSource" AutoGenerateColumns="False" AllowSorting="True" BorderWidth="2px"
BackColor="White" GridLines="None" CellPadding="3" CellSpacing="1" BorderStyle="Ridge" BorderColor="White" AllowPaging="True">
<FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
<PagerStyle ForeColor="Black" HorizontalAlign="Right" BackColor="#C6C3C6"></PagerStyle>
<HeaderStyle ForeColor="#E7E7FF" Font-Bold="True" BackColor="#4A3C8C"></HeaderStyle>
<Columns>
<asp:BoundField HeaderText="Product" DataField="ProductName" SortExpression="ProductName"></asp:BoundField>
<asp:BoundField HeaderText="Unit Price" DataField="UnitPrice" SortExpression="UnitPrice" DataFormatString="{0:c}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Units In Stock" DataField="UnitsInStock" SortExpression="UnitsInStock" DataFormatString="{0:d}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Quantity Per Unit" DataField="QuantityPerUnit"></asp:BoundField>
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True" BackColor="#9471DE"></SelectedRowStyle>
<RowStyle ForeColor="Black" BackColor="#DEDFDE"></RowStyle>
</asp:GridView>
This table only has one row in the column header. What I am looking for is something like this:
Any Ideas on how I can achieve this? Is this even possible?
If you use a TemplateField instead, you can control the header template as well, which can be custom ASPX markup. The downside is that you have to display the data manually with Labels instead of using the simpler BoundField properties. However, this also allows you to layout the data in a custom layout to fit with the heading:
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Weight<br />
Date | Time<br />
Product
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("Weight") %>'></asp:Label><br />
<asp:Label runat="server" Text='<%#Eval("Date") %>'></asp:Label> |
<asp:Label runat="server" Text='<%#Eval("Time") %>'></asp:Label><br />
<asp:Label runat="server" Text='<%#Eval("Product") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
I am trying to upgrade an ASP.NET application to .NET 4, but one page on my site contains an exception:
Argument Exception: an entry with the same key already exists".
What is different about ASP.NET 4 that might cause this problem?
One Solution
Not sure why but setting clientIDMode="Predictable" rather than Static seems to have avoided this exception message.
I had the same issue and fixed it.
I went through my entire ASPX page and found ASP.NET control that had the same ID as another.
I also tested this fix, and found that any control that conflicts with another control on the page will cause this error.
<asp:Label ID="FailureText" runat="server" EnableViewState="False" ClientIDMode="Static" />
<asp:Label ID="FailureText" runat="server" EnableViewState="False" ClientIDMode="Static" />
It happens when you Copy/Paste elements on the same page.
This in your web.config may also cause the error by allowing duplicate IDs
<pages clientIDMode="Static">
I have this error too and not resolve with this
<pages clientIDMode="Static">
my datagrid work fine this :
I have gridview :
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Button" CancelText="لغو" DeleteText="حذف" EditText="ويرايش" UpdateText="بروزرساني">
<ControlStyle CssClass="btn btn-xs btn-default" />
<ItemStyle Width="143px" />
</asp:CommandField>
<asp:BoundField DataField="ID" HeaderText="#" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Title" HeaderText="عنوان" SortExpression="Title" />
<asp:BoundField DataField="ParentID" HeaderText="پدر" SortExpression="ParentID" />
<asp:BoundField DataField="Url" HeaderText="آدرس" SortExpression="Url">
<ItemStyle CssClass="ltr"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Icon" HeaderText="آيکون" SortExpression="Icon" />
<asp:BoundField DataField="Order" HeaderText="اولويت" SortExpression="Order" />
</Columns>
</asp:GridView>
but after add image field i see this error
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Button" CancelText="لغو" DeleteText="حذف" EditText="ويرايش" UpdateText="بروزرساني">
<ControlStyle CssClass="btn btn-xs btn-default" />
<ItemStyle Width="143px" />
</asp:CommandField>
<asp:ImageField ReadOnly="true" SortExpression="Icon" DataImageUrlField="icon">
</asp:ImageField>
<asp:BoundField DataField="ID" HeaderText="#" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Title" HeaderText="عنوان" SortExpression="Title" />
<asp:BoundField DataField="ParentID" HeaderText="پدر" SortExpression="ParentID" />
<asp:BoundField DataField="Url" HeaderText="آدرس" SortExpression="Url">
<ItemStyle CssClass="ltr"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Icon" HeaderText="آيکون" SortExpression="Icon" />
<asp:BoundField DataField="Order" HeaderText="اولويت" SortExpression="Order" />
</Columns>
</asp:GridView>
I have gridview that I am using paging on. I want to pass along the current page in a asp:Hyperlink so I can send them back to the current page when they are done viewing the details of a record. Is this possible? If it is how can I do this?
<asp:GridView ID="grdObitList" runat="server" allowpaging="true"
PageSize="10" AutoGenerateColumns="false" CssClass="grdClass"
BorderStyle="None" GridLines="None" CellSpacing="2" >
<PagerStyle HorizontalAlign="Center" />
<PagerSettings Position="Bottom" FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast" />
<Columns>
<asp:HyperLinkField HeaderText="Name" DataTextField="obit_fullname" DataNavigateUrlFields="obit_id" DataNavigateUrlFormatString="obitDisplay.aspx?oid={0}" />
<asp:BoundField ReadOnly="true" HeaderText="Date" DataField="obit_dod" DataFormatString="{0:d/M/yyyy}" />
<asp:BoundField ReadOnly="true" HeaderText="Resident Of" DataField="obit_resident" />
<asp:BoundField ReadOnly="true" HeaderText="Funeral Home" DataField="obit_funeralhome" />
</Columns>
One way to do it is converting it to a template column, that way you can use normal databind syntaxt to get to it (<%#)