I have the If-Then statement on the ShowAd.aspx page where if the Price=0 the "Call for Price" is displayed. However, I am not able to locate where to place a similar If-Then statement for the Search.aspx page where all of the listings for a particluar
category are displayed by rows.
That code should be in code-behind (Search.aspx.cs).. It is written based on the assumption that the ID of your GridView is ResultsGridView and the column number is 6.. Make necessary changes.. If you paste your GridView code I can give you accurate code..
<asp:GridView ID="AdsGrid" runat="server" DataSourceID="AdSearchDataSource" AutoGenerateColumns="False"
DataKeyNames="Id" AllowPaging="True" PageSize="15" AllowSorting="True" BorderWidth="0px"
CssClass="item_list">
<EmptyDataTemplate>
No Ads were found matching your query.
</EmptyDataTemplate>
iamsaltman
Member
24 Points
43 Posts
Show text if price=0 on Search page
Mar 04, 2011 05:08 AM|LINK
I have the If-Then statement on the ShowAd.aspx page where if the Price=0 the "Call for Price" is displayed. However, I am not able to locate where to place a similar If-Then statement for the Search.aspx page where all of the listings for a particluar category are displayed by rows.
Any suggestions?
Thanks, Tim
s_selvan
Member
386 Points
79 Posts
Re: Show text if price=0 on Search page
Mar 04, 2011 09:43 AM|LINK
put your condition to itemdatabound event of the grid
jerryjoseph
Contributor
7012 Points
1300 Posts
Re: Show text if price=0 on Search page
Mar 04, 2011 09:58 AM|LINK
Assuming that you have to display it in the 6th column
void ResultsGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // display "Call for Price" if Price=0 if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Price")) == 0) { e.Row.Cells[5].Text = "Call for Price"; } } }linkedin | twitter | www.jerryjoseph.net
Lyra Belaqua
Contributor
2673 Points
552 Posts
Re: Show text if price=0 on Search page
Mar 04, 2011 10:07 AM|LINK
Hi,
You can even get direct value from SQL itself also with CASE statement.
Bind the Price column in listing.
Hope it helps.
Please don't forget to click "Mark as Answer" on the post that helped you.
Before printing, think about the environment, every 3000 A4 paper costs 1 tree.
jerryjoseph
Contributor
7012 Points
1300 Posts
Re: Show text if price=0 on Search page
Mar 04, 2011 10:16 AM|LINK
You have to decide where to handle this logic (code-behind / Entity class / stored procedure) based on the architecture you follow.
linkedin | twitter | www.jerryjoseph.net
iamsaltman
Member
24 Points
43 Posts
Re: Show text if price=0 on Search page
Mar 05, 2011 08:33 PM|LINK
@JerryJoseph - Where is this code placed?
Thanks for the help.
jerryjoseph
Contributor
7012 Points
1300 Posts
Re: Show text if price=0 on Search page
Mar 06, 2011 02:35 AM|LINK
linkedin | twitter | www.jerryjoseph.net
iamsaltman
Member
24 Points
43 Posts
Re: Show text if price=0 on Search page
Mar 08, 2011 04:55 PM|LINK
<asp:GridView ID="AdsGrid" runat="server" DataSourceID="AdSearchDataSource" AutoGenerateColumns="False"
DataKeyNames="Id" AllowPaging="True" PageSize="15" AllowSorting="True" BorderWidth="0px"
CssClass="item_list">
<EmptyDataTemplate>
No Ads were found matching your query.
</EmptyDataTemplate>
<Columns>
<asp:ImageField DataImageUrlFormatString="~/PhotoDisplay.ashx?photoid={0}&size=small"
DataImageUrlField="PreviewImageId" SortExpression="PreviewImageId" AlternateText="Ad preview photo.">
<ItemStyle CssClass="col_photo" />
<HeaderStyle CssClass="col_photo" />
</asp:ImageField>
<asp:BoundField HeaderText="Start Date" DataField="DateCreated" SortExpression="DateCreated"
DataFormatString="{0:MM/dd/yy}" HtmlEncode="False">
<ItemStyle CssClass="col_startdate" />
<HeaderStyle CssClass="col_startdate" />
</asp:BoundField>
<asp:HyperLinkField HeaderText="Title" DataNavigateUrlFields="Id" DataNavigateUrlFormatString="~/ShowAd.aspx?id={0}"
DataTextField="Title" SortExpression="Title">
<ItemStyle CssClass="col_title" />
<HeaderStyle CssClass="col_title" />
</asp:HyperLinkField>
<asp:BoundField HeaderText="Price" DataField="Price" SortExpression="Price" DataFormatString="{0:c2}"
HtmlEncode="False">
<ItemStyle CssClass="col_price" />
<HeaderStyle CssClass="col_price" />
</asp:BoundField>
<asp:BoundField HeaderText="Location" DataField="Location" SortExpression="Location">
<ItemStyle CssClass="col_location" />
<HeaderStyle CssClass="col_location" />
</asp:BoundField>
<asp:BoundField HeaderText="Category" DataField="CategoryName" SortExpression="CategoryName">
<ItemStyle CssClass="col_category" />
<HeaderStyle CssClass="col_category" />
</asp:BoundField>
<asp:BoundField HeaderText="Condition" DataField="Condition" SortExpression="Condition">
<ItemStyle CssClass="col_location" />
<HeaderStyle CssClass="col_location" />
</asp:BoundField>
<%--<asp:TemplateField SortExpression="Title" HeaderText="Type">
<ItemTemplate>
<%# OutputFormatting.AdTypeToString(Eval("AdType")) %>
</ItemTemplate>
<ItemStyle CssClass="col_general" />
<HeaderStyle CssClass="col_general" />
</asp:TemplateField>--%>
</Columns>
<RowStyle CssClass="row1"></RowStyle>
<AlternatingRowStyle CssClass="row2"></AlternatingRowStyle>
<PagerStyle CssClass="item_list_footer" />
</asp:GridView>
jerryjoseph
Contributor
7012 Points
1300 Posts
Re: Show text if price=0 on Search page
Mar 08, 2011 05:23 PM|LINK
Add the databound event to the Grid in Search.aspx
Search.aspx.cs should contain the method below.
protected void AdsGrid_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // display "Call for Price" if Price=0 if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Price")) == 0) { e.Row.Cells[3].Text = "Call for Price"; } } }linkedin | twitter | www.jerryjoseph.net
iamsaltman
Member
24 Points
43 Posts
Re: Show text if price=0 on Search page
Mar 08, 2011 09:28 PM|LINK
@jerryJoseph - Thanks for all the help but I am now receiving an "End of statement expected" error in my code behind.
Tim