How can I conditionally put an image into a cell on my ASPxGridView. For example; if Column1 is above 1000 I would like to see 'above.png' on Column2, if below 1000 i want to see 'below.png' on Column2.
Here is the markup for my ASPXGridView:
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="pkCalisan" Width="100%" >
<Columns>
<dx:GridViewDataTextColumn
FieldName="ID"
ReadOnly="True"
VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Price" VisibleIndex="1"></dx:GridViewDataTextColumn>
<dx:GridViewDataImageColumn VisibleIndex="2"></dx:GridViewDataImageColumn>
</Columns>
</dx:ASPxGridView>
Thanks..
Define a custom image control inside the column's DataItemTemplate and manage the image's properties (visibility or image URL) at runtime.
See the E2270 Example that illustrates how to manage the hyperlink's properties in a similar scenario.
Related
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
I am trying to have a gridview which has fixed columns width. Right now the columns that have no value are too narrow. This grid is being populated with a datatable on a button click
Could you please suggest the solution.
for BoundField use the property ItemStyle-Width:
<asp:BoundField DataField="UserName" HeaderText="User Name" ItemStyle-Width="50px" />
I have a multiple Parent-Child Gridview. The problem is Parent gridview Column name is Cost ($) and the ($) symbol is hiding when i expand the Child gridview and get it back when i minimize the Child gridview (Devexpress). The Parent-Child gridview is present in the AspxCallbackPanel and in the PopupControl.
<dx:ASPxCallbackPanel ID="cbpCartDetails" runat="server"
OnCallback="cbpCartDetails_Callback" ClientInstanceName="cbpCartDetails">
<ClientSideEvents EndCallback="cbpCartDetails_EndCallBack" />
<PanelCollection>
<dx:PanelContent ID="pnlCartDetails">
<dx:ASPxPopupControl ClientInstanceName="popCartDetails" Width="600px"
Height="250px" CloseAction="CloseButton" MaxWidth="800px" MaxHeight="800px"
MinHeight="150px" MinWidth="150px" ID="popCartDetails"
HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="true"
runat="server" EnableViewState="false" PopupHorizontalAlign="WindowCenter"
PopupVerticalAlign="WindowCenter" EnableHierarchyRecreation="false"
Modal="true">
<ContentCollection>
<dx:PopupControlContentControl ID="PopupControlContentControl2"
runat="server">
<dx:ASPxGridView ID="grdBuildingCartEst" Width="100%"
Theme="SoftOrange" KeyFieldName="CarttypeId"
ClientInstanceName="grdBuildingCartEst">
<Columns>
<dx:GridViewDataTextColumn FieldName="CartType" />
<dx:GridViewDataTextColumn FieldName="NumberOfCart" />
<dx:GridViewDataTextColumn FieldName="Cost" />
</Columns>
<Templates>
<DetailRow>
<dx:ASPxGridView ID="grdFloorsCartEst"
Width="100%"
Theme="SoftOrange"
KeyFieldName="CarttypeId"
OnInit="grdFloorsCartEst_Init"
OnBeforePerformDataSelect=
"grdFloorsCartEst_BeforePerformDataSelect"
ClientInstanceName="grdFloorsCartEst">
<Columns>
<dx:GridViewDataTextColumn
FieldName="CartSize" />
<dx:GridViewDataTextColumn
FieldName="NumberOfCart" />
<dx:GridViewDataTextColumn
FieldName="Cost" />
</Columns>
</dx:ASPxGridView>
</DetailRow>
</Templates>
<SettingsDetail ShowDetailRow="true" />
</dx:ASPxGridView>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>
</dx:PanelContent>
</PanelCollection>
Screen shot 1
https://i.stack.imgur.com/Fb1QX.png
Screen shot 2 (Error)
https://i.stack.imgur.com/AghdG.png
notice, in the code you've posted, there is no "Cost ($)" string for the master grid column, only FieldName="Cost". Most probably "Cost ($)" is set to column header at codebehind during Page_Load or some other event.
When you expand the child grid there happens a callback and the event code at codebehind where you set Cost ($) is not executed. So, you need to make sure the column header of the master grid is set to "Cost ($)" during child grid expand callback. To be 100% sure, post/attach the codebehind part of your page/control to the question's text.
I have a gridview that is databound to a XmlDataSource. I also want to add a <columns> section with a buttonfield at the end of the gridview. When I add a columns section it prepends it (before xml columns). How could I order
<asp:XmlDataSource ID="xmlDataSource1" runat="server"
datafile="some.xml" TransformFile="some.xslt" />
<asp:GridView ID="linksGrid" runat="server"
DataSourceID="xmlDataSource1"
CssClass="adminGrid"
AllowPaging="True"
AlternatingRowStyle-BackColor="WhiteSmoke">
<Columns>
<asp:ButtonField runat="server" ButtonType="Button" Text="details" />
</Columns>
</asp:GridView>
this produces a table like this:
I want the order to be reversed: Title, Url, Button column
bones question, how could I space the columns so the modify button has no weight (fits to column) and the remaining cells to get even space?
The code below will surely help you.
<asp:GridView ID="MyGridView" runat="server" ShowFooter="True">
<Columns>
<asp:TemplateField >
<FooterTemplate >
<asp:Button ID="MyButton" runat="server" Text="Click Me"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The trick was
<asp:GridView AutoGenerateColumns="false .. />
I could simply use a asp:BoundField in my < columns > section to specify the order.
I will leave this open a bit if someone can provide an answer on how to CSS format individual columns.
I have a gridview that I populate based on a query to a db. I'm trying to add sorting on my gridview but I cannot make my column headers clickable. I have allow sorting set to true, and I have my OnSorting event set. My columns are of a few different types. I know the code I need to have in my code behind, but I cannot click on the headers for some reason. Any help on what I'm missing would be appreciated.
<asp:GridView ID="Grid1" runat="server"
AutoGenerateColumns="False"
OnSelectedIndexChanging="Selected_Row_Changing"
DataKeyNames="ApplicationId"
AllowPaging="True"
OnPageIndexChanging="Grid1_PageIndexChanging"
AllowSorting="True"
OnSorting="Grid1_Sorting"
OnRowCreated="OnRowCreated"
OnRowCommand="Grid1_RowCommand"
OnRowDataBound="Grid1_RowDataBound">
<Columns>
<asp:templatefield ...>
<itemtemplate>
<asp:linkbutton .../>
</itemtemplate>
</asp:templatefield>
<asp:BoundField ... />
<asp:HyperLinkField ... />
<asp:ButtonField ... />
</Columns>
</asp:GridView>
You don't have set the SortExpression, have you?
For example:
<asp:boundfield datafield="CompanyName"
headertext="CompanyName"
headerstyle-wrap="false"
sortexpression="CompanyName"/>
Make sure you're not setting the Header Template but rather set the HeaderText attribute for the TemplateField
I'm using a DevExpress grid and I'm trying to get a 'Country' column to display the header filter properly:
<dx:GridViewDataColumn Caption="Country" FieldName="CountryName"
ShowInCustomizationForm="True" Visible="false">
<Settings AllowHeaderFilter="True"/>
</dx:GridViewDataColumn>
If the 'Country' column is set to Visible='true', then the header filter is displayed as it should(it shows the value option list). However, I want the 'Country' column to be initially hidden, but available in a Customization window(like in the code above). In this case, when the column is dragged outside the Customization window and into the grid and the header filter is clicked, a Javascript error is encountered:
element is null
element.addEventListener(eventName, func, true);
Is this a known bug? Are there any workarounds?
Set the ASPxGridView.Settings.ShowHeaderFilterButton property to true to resolve this problem.
The following markup works fine for me (I am using DXperience 10.1.7):
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT * FROM [Categories]"></asp:AccessDataSource>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" ClientInstanceName="grid"
DataSourceID="AccessDataSource1" KeyFieldName="CategoryID">
<SettingsCustomizationWindow Enabled="True" />
<Columns>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False"/>
<Settings AllowHeaderFilter="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName" Visible="False" VisibleIndex="1">
<Settings AllowHeaderFilter="True" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
<Settings AllowHeaderFilter="False" />
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowHeaderFilterButton="True" />
</dx:ASPxGridView>