replacing strings - c#

here i need to replace content "says..." :
<asp:DataList ID="dlProductReviews" runat="server" RepeatDirection="Vertical" RepeatColumns="1">
<ItemTemplate>
<div>
<span class="content">says... </span>
</div>
</ItemTemplate>
</asp:DataList>

You can use the data binding tags here:
<asp:DataList ID="dlProductReviews" runat="server" RepeatDirection="Vertical" RepeatColumns="1">
<ItemTemplate>
<div>
<span class="content"><%# GetContent() %></span>
</div>
</ItemTemplate>
</asp:DataList>
Then in your code behind create a protected method called GetContent()(or you could use a property) in the code behind that returns a string, in your case a string from the resources. You could also place the code directly in the <%#...%> tags.

Related

Need to add 'for' attibutes to labels inside a ListView control of an ASP.NET page

I have something like this
<asp:ListView ID="lvOptions" runat="server"">
<LayoutTemplate>
<p>Select an option<span>*</span></p>
<div class="row">
<asp:Literal runat="server" ID="groupPlaceHolder"></asp:Literal>
</div>
<div class="row">
<div class="w100">
<label>
Other types:</label>
<asp:DropDownList ID="ddlOtherTypes" runat="server" DataTextField="Description" DataValueField="Id"
AutoPostBack="true" Enabled="false"
</asp:DropDownList>
</div>
</div>
</LayoutTemplate>
<GroupTemplate>
<asp:Literal runat="server" ID="itemPlaceHolder"></asp:Literal>
</GroupTemplate>
<ItemTemplate>
<span class="wrap-w50">
<asp:RadioButton runat="server" ID="rdbOption" AutoPostBack="true" />
<label>
<%# Eval("Description") %></label>
</span>
</ItemTemplate>
</asp:ListView>
And I got here two labels, one fot the Other types DropDownList, and another for each RadioButton.
For this labels, I need to add a "for" attribute, and I need the clientID but, if I try to write the attibute like:
for="<%= ddlOtherTypes.ClientID %>"
for="<%= rdbOption.ClientID %>"
I got the error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Any suggestions please?
Thank you in advance.

ASP.NET: The server tag is not well formed

I have been trying to get a progressBar into my GridView for a while now. Unfortunately without success. I currently have the following:
<asp:GridView ID="gvShow" runat="server" AutoGenerateColumns="False" DataKeyNames="Progress" Width="100%">
<Columns>
<asp:BoundField DataField="Progress" HeaderText="Progress" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Literal ID="lbProgress" runat="server" Text="<div class='progress'><div class='progress-bar' role='progressbar' aria-valuenow='<%#Eval("Progress") %>' aria-valuemin='0' aria-valuemax='100' style='width: 60%;'><span class='sr-only'>60% Complete</span></div></div>"></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
which results in a parser error (The server tag is not well formed.). If I replace the eval with any value it works without any issues. I think I am missing something here but I really can't find it.
For some reason all of your markup is as text of Literal control. So you have the problem with quotes, as you need double quotes for Text="" and of Eval.
Personally I see no reason to use Literal here, you can just use the markup as is, and the problem will go away:
<ItemTemplate>
<div class='progress'>
<div class='progress-bar' role='progressbar' aria-valuenow='<%#Eval("Progress") %>' aria-valuemin='0' aria-valuemax='100' style='width: 60%;'>
<span class='sr-only'>60% Complete</span>
</div>
</div>
</ItemTemplate>
You have to use Eval method instead of Text Method.
<ItemTemplate>
<div class='progress'>
<div class='progress-bar' role='progressbar' aria-valuenow='<%#Eval("Progress") %>' aria-valuemin='0' aria-valuemax='100' style='width: 60%;'>
<span class='sr-only'>60% Complete</span>
</div>
</div>

Multilingual pages and dynamic multilingual content

I am creating a web app that has multilingual pages in dynamic multilingual contents or pages as well. The problem is actually with multilingual contents. When I use visible prop or the repeater component then it works well, but the problem when writes a lot of code, I think there must be a simpler way for this?
<!--Turkish-->
<asp:ListView runat="server" ID="lvListAllProdsTr">
<ItemTemplate>
<div class="gallery_box">
<a rel="lightbox[portfolio]" href='<%# Eval("ImgUrl") %>' title='<%# Eval("ProdNameTr") %>'>
<img src='<%# Eval("ImgUrl") %>' />
</a>
<h3>
<a href="#">
<%# Eval("ProdNameTr") %>
</a>
</h3>
<a href="#" class="more">
<asp:Literal ID="ltrDetayTr" Text="Detay" runat="server" /></a>
<div class="cleaner">
</div>
</div>
</ItemTemplate>
</asp:ListView>
<asp:DataPager ID="dpTr" runat="server" PagedControlID="lvListAllProdsTr" PageSize="10">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
<!--Turkish-->
<!--Russian-->
<asp:ListView runat="server" ID="lvListAllProdsRu">
<ItemTemplate>
<div class="gallery_box">
<a rel="lightbox[portfolio]" href='<%# Eval("ImgUrl") %>' title='<%# Eval("ProdNameRu") %>'>
<img src='<%# Eval("ImgUrl") %>' />
</a>
<h3>
<a href="#">
<%# Eval("ProdNameRu") %>
</a>
</h3>
<a href="#" class="more">
<asp:Literal ID="ltrDetayTr" Text="Detay" runat="server" /></a>
<div class="cleaner">
</div>
</div>
</ItemTemplate>
</asp:ListView>
<asp:DataPager ID="dpRu" runat="server" PagedControlID="lvListAllProdsRu" PageSize="10">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
<!--Russian-->
instead of Eval("ProdNameTr") how about calling a method for example :
GetProductName(Container.DataItem)
inside this method you read the current locale (if you know by then from the culture or something) and return the appropriate value

How can I access the textbox value

<asp:DataList id="ItemsList"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Table"
RepeatColumns="3"
runat="server">
<ItemTemplate>
<a href="#" data-inline="true" data-role="button"
data-icon="star" data-iconpos="right">
<input type="text" id="txtTry" style="width: 20%" runat="server"
value="" data-mini="true"
<%# DataBinder.Eval(Container.DataItem, "StringValue") %>
</a>
</ItemTemplate>
</asp:DataList>
how can I access the value of the text box of each button in the CS. How can I access it.This is not tough but I didn't use it yet.
You need to change HTML controls <input>
to the ASP.NET controls, for example:
<asp:TextBox ID="txtTry" runat="server"></asp:TextBox>
Then later in your .cs file you can change the value of the textbox:
...
txtTry.Text = "foo";
...
yes change the html to Asp.net text box. Then you can get via method mentioned by oleksii
Even with input html text try the below sample It should normally be done with
Request.Form["elementName"]
For example, if you have
<input type="text" name="try" /> then you can use Request.Form["try"] to access its value.

ASP.NET outputting <br> tags?

I'm working on a website built in .net and its outputting linbreaks after each span for some reason. The code thats outputting the line breaks is
<asp:DataList ID="DL_Items" runat="server" DataKeyField="ProductID" oneditcommand="DL_Items_EditCommand"
oncancelcommand="DL_Items_CancelCommand"
onupdatecommand="DL_Items_UpdateCommand"
onitemcommand="DL_Items_ItemCommand"
onitemdatabound="DL_Items_ItemDataBound"
ondeletecommand="DL_Items_DeleteCommand" RepeatLayout="Flow">
<ItemTemplate>
I've tried looking around google for better solutions to this and all I could find was a way to generate the code in a table which i do not want. Is there a reason why the above code is generating line breaks, <br>
Compete itemtemplate
<ItemTemplate>
<div class="EC_Item_Left_Panel">
<ul class="EC_Item_Left_UL">
<li>
<asp:Image ID="IM_PIC" runat="server" ImageUrl='<%# Eval("path") %>' /></li>
<li>
<asp:LinkButton ID="BT_Edit" CssClass="ecom_edit_tbn" CommandName="Edit" runat="server">Edit Item</asp:LinkButton></li>
<li class="deleteRow">
<asp:LinkButton ID="BT_Delete" ToolTip='<%# Eval("ProductName") %>' runat="server" CssClass="deleteButton ecom_remove_tbn" Text="Delete" ForeColor="Red"></asp:LinkButton>
<asp:Button ID="deleteCommand" runat="server" CausesValidation="false" CommandName="Delete" CssClass="deleteCommand" style="display:none" />
</li>
<%--<asp:LinkButton CssClass="ecom_remove_tbn" ID="BT_Remove" CommandName="Delete" runat="server">Remove</asp:LinkButton>--%>
<li><asp:LinkButton CssClass="ecom_link_tbn" ID="BT_Link" runat="server" CommandName="linkproduct">Linked Items</asp:LinkButton></li>
</ul>
</div>
<div>
<div class="Item_Right_Panel">
<ul class="EC_Item_Top_UL">
<li><label>ProductID </label><span><%#Eval("ProductID")%></span></li>
<li><label>Enabled </label><span><%#Eval("Enabled")%></span></li>
<li><label>Title </label><asp:Label ID="LB_ProductTitle" runat="server" Text='<%#Eval("ProductName")%>'></asp:Label></li>
<li><label>Product Code </label><span><%#Eval("ProductCode")%></span></li>
<li><label>Category </label><span><%#Eval("Category")%></span></li>
<%--Callum--%>
<li><label>Price</label><span><%#Eval("Sale_Price")%></span></li>
<li><label>Subcategory</label><span><%#Eval("Subcat")%></span></li>
<li><label>Designer</label><span><%#Eval("DesignerName")%></span></li>
<li><label>Range</label><span><%#Eval("Range")%></span></li>
<li><label>Height</label></li>
<li><label>Length</label></li>
<li><label>Width</label></li>
<li><label>Description </label><span><%#Eval("Description")%></span></li>
</ul>
<ul class="EC_Item_Bottom_UL">
<li><label>KeyFieldName </label><span><%#Eval("KeyFieldName")%></span></li>
<li><label>ItemField1Name </label><span><%#Eval("ItemField1Name")%></span></li>
<li><label>ItemField2Name </label><span><%#Eval("ItemField2Name")%></span></li>
<li><label>ItemField3Name </label><span><%#Eval("ItemField3Name")%></span></li>
<li><label>ItemField3Name </label><span><%#Eval("ItemField3Name")%></span></li>
<li><label>Include File </label><span> <%# IncludeTitle(DataBinder.Eval(Container.DataItem, "include"))%> </span></li>
</ul>
</div>
</div>
</ItemTemplate>
The DataList creates the br's(See documentation of Flow layout at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeatlayout%28v=VS.100%29.aspx).
If you don't want br's or any extra markup between elements, I'd suggest you to use a Repeater instead.

Categories

Resources