I have a problem with an updatepanel when I put it inside a repeater control I get an error, and I need to refresh only a single post when the user click on a link button, here is my code...
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server"
OnItemCommand="MyButtonCommandEvent">
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<div class="post">
<asp:HiddenField ID="postID_hidden" runat="server"
Value='<%# DataBinder.Eval(Container.DataItem,"posts_ID") %>' />
<div class="Thumb">
<img src="thumbs/abdo_thumb.jpg"> </img></div>
<span class="user"><%#DataBinder.Eval(Container.DataItem, "poster_name")%>
</span>
<div class="post-body">
<p>
<%#DataBinder.Eval(Container.DataItem,"description")%>
</p>
</div>
<div class="post-options" style=" height:22px; ">
<span class="first"><%#DataBinder.Eval(Container.DataItem,"post_date")%></span>
<ul style="display:inline; list-style-type: none;">
<li>
<div class="tooltip">
Comments
<img class="tool-img" src="Images/comments.png"> : <%#DataBinder.Eval(Container.DataItem,"comment_num") %>
</img>
</div>
</li>
<li>
<div class="tooltip">
<asp:LinkButton ID="like_linkbtn" runat="server" CommandName="Like"><%#(DataBinder.Eval(Container.DataItem, "name_like").ToString() == "") ? "Like" : DataBinder.Eval(Container.DataItem, "name_like")%></asp:LinkButton>
<img class="tool-img" src="images/likes.png"> : <%#DataBinder.Eval(Container.DataItem,"like_counter") %>
</img></div>
</li>
<li>
<div class="tooltip">
<asp:LinkButton ID="hate_linkbtn" runat="server" CommandName="Hate"><%#(DataBinder.Eval(Container.DataItem, "name_hate").ToString() == "") ? "Hate" : DataBinder.Eval(Container.DataItem, "name_hate")%></asp:LinkButton>
<img class="tool-img" src="images/hate.png"> : <%#DataBinder.Eval(Container.DataItem,"hate_counter") %>
</img></div>
</li>
</ul>
</div>
<div class="finish">
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
The error is : Compiler Error Message: CS1061: 'System.Web.UI.Control' does not contain a definition for 'DataItem' and no extension method 'DataItem' accepting a first argument of type 'System.Web.UI.Control' could be found (are you missing a using directive or an assembly reference?).
This is making me really frustrated please help.
PS: It works if I removed the updatepanel and made it outside the repeater (The repeater inside the updatepanel instead of the updatepanel inside the repeater but that's not what I want)
Another solution is to cast Container as IDataItemContainer (((IDataItemContainer)Container)).
Instead of:
<%# DataBinder.Eval(Container.DataItem, "Column") %>
Use:
<%# DataBinder.Eval(((IDataItemContainer)Container).DataItem, "Column") %>
This solution is ideal if you are casting the DataItem as an object, eg:
<%# ((MyClass)Container.DataItem).ColumnName %>
This becomes:
<%# ((MyClass)((IDataItemContainer)Container).DataItem).ColumnName %>
Put Update panel out side of repeater. It will work.
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server"
OnItemCommand="MyButtonCommandEvent">
<ItemTemplate>
<div class="post">
<asp:HiddenField ID="postID_hidden" runat="server"
Value='<%# DataBinder.Eval(Container.DataItem,"posts_ID") %>' />
<div class="Thumb">
<img src="thumbs/abdo_thumb.jpg"> </img></div>
<span class="user"><%#DataBinder.Eval(Container.DataItem, "poster_name")%>
</span>
<div class="post-body">
<p>
<%#DataBinder.Eval(Container.DataItem,"description")%>
</p>
</div>
<div class="post-options" style=" height:22px; ">
<span class="first"><%#DataBinder.Eval(Container.DataItem,"post_date")%></span>
<ul style="display:inline; list-style-type: none;">
<li>
<div class="tooltip">
Comments
<img class="tool-img" src="Images/comments.png"> : <%#DataBinder.Eval(Container.DataItem,"comment_num") %>
</img>
</div>
</li>
<li>
<div class="tooltip">
<asp:LinkButton ID="like_linkbtn" runat="server" CommandName="Like"><%#(DataBinder.Eval(Container.DataItem, "name_like").ToString() == "") ? "Like" : DataBinder.Eval(Container.DataItem, "name_like")%></asp:LinkButton>
<img class="tool-img" src="images/likes.png"> : <%#DataBinder.Eval(Container.DataItem,"like_counter") %>
</img></div>
</li>
<li>
<div class="tooltip">
<asp:LinkButton ID="hate_linkbtn" runat="server" CommandName="Hate"><%#(DataBinder.Eval(Container.DataItem, "name_hate").ToString() == "") ? "Hate" : DataBinder.Eval(Container.DataItem, "name_hate")%></asp:LinkButton>
<img class="tool-img" src="images/hate.png"> : <%#DataBinder.Eval(Container.DataItem,"hate_counter") %>
</img></div>
</li>
</ul>
</div>
<div class="finish">
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
Related
I am trying to use if else conditions in aspx page using Eval conditions. But its showing error red line in else condition and in ) in if condition.
Code
<div class="price_mth text-center">
<% if (string.IsNullOrEmpty(Eval("PromoPrice", "{0:,00}").ToString()) %>) { %>
<asp:panel id="pricePanel" runat="server" >
<h2><i class="fa fa-usd" aria-hidden="true"></i> <%# Eval("Price", "{0:,00}") %><sup>.00/mo</sup></h2>
</asp:panel>
<% } %>
<% else { %>
<asp:panel id="promopanel" runat="server">
<div class="style-1">
<h2> <del><i class="fa fa-usd" aria-hidden="true"></i> <span class="amount"><%# Eval("Price", "{0:,00}") %></span> </del><sup>.00/mo</sup></h2>
<h2><ins><i class="fa fa-usd" aria-hidden="true"></i> <span class="amount"><%# Eval("PromoPrice", "{0:,00}") %></span></ins><sup>.00/mo</sup></h2>
</div>
</asp:panel>
<% } %>
You can use a method as shown below:
<asp:Panel ID="p1" Visible='<%# BLL.Logic.ShowPanel(Eval("PromoPrice", "{0:,00}")) %>' runat="server">
</asp:Panel>
I'm developing a blog that has a section for getting some comments and replies from the users. The first part is of my code for getting the comments and replies is the following one:
C# code:
var a = commentBLL.GetAll(BlogID);
rp_MainComments.DataSource = a;
rp_MainComments.DataBind();
protected void rp_MainComments_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton btn = e.Item.FindControl("btn_Comment_Reply") as LinkButton;
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(btn);
HiddenField lt = (HiddenField)e.Item.FindControl("hf_Main_CommentID");
Repeater rpcommentreply = (Repeater)e.Item.FindControl("rp_Comment_Reply");
Panel panel_Comment_Reply = e.Item.FindControl("panel_Comment_Reply") as Panel;
if (!string.IsNullOrEmpty(lt.Value))
{
var b = commentBLL.GetByCommentID(Convert.ToInt32(lt.Value));
rpcommentreply.DataSource = b;
rpcommentreply.DataBind();
panel_Comment_Reply.Visible = false;
}
}
}
ASPX code:
<asp:Repeater ID="rp_MainComments" OnItemDataBound="rp_MainComments_ItemDataBound" OnItemCommand="rp_MainComments_ItemCommand" runat="server">
<ItemTemplate>
<asp:HiddenField ID="hf_Main_CommentID" runat="server" Value='<%# Eval("Comment_Id") %>' />
<ul class="comments">
<li>
<div class="comment">
<div class="img-thumbnail d-none d-sm-block">
<%--<asp:Image ID="Image_7" CssClass="avatar" runat="server" ImageUrl="http://placehold.it/40x40" />--%>
<i class="fa fa-user fa-fw fa-5x"></i>
</div>
<div class="comment-block">
<div class="comment-arrow"></div>
<span class="comment-by">
<strong><%# Eval("Name") %></strong>
<span class="float-right">
<span>
<asp:LinkButton ID="btn_Comment_Reply" Text="Reply" ClientIDMode="AutoID" runat="server" OnClick="btn_Comment_Reply_Click" CommandName="Edit" CommandArgument='<%# Eval("Comment_Id") %>' /></span>
</span>
</span>
<p><%# Eval("Message") %></p>
<span class="date float-right">
<%# Eval("Comment_Date") %></span>
</div>
</div>
</li>
<li>
<asp:HiddenField ID="hf_PanelValue" Value='<%# Container.ItemIndex %>' runat="server" />
<asp:Repeater ID="rp_Comment_Reply" OnItemCommand="rp_Comment_Reply_ItemCommand" runat="server">
<ItemTemplate>
<ul class="comments reply" id="commentreply">
<li>
<div class="comment">
<div class="img-thumbnail d-none d-sm-block">
<%--<asp:Image ID="Image_8" CssClass="avatar" runat="server" ImageUrl="http://placehold.it/40x40" />--%>
<i class="fa fa-user fa-5x fa-fw"></i>
</div>
<div class="comment-block">
<div class="comment-arrow"></div>
<span class="comment-by">
<strong><%# Eval("Name") %></strong>
<span class="float-right">
<span>
<asp:LinkButton ID="btn_Reply" Text="Reply" ClientIDMode="AutoID" runat="server" OnClick="btn_Reply_Click" CommandName="Edit" CommandArgument='<%# Eval("Parent_Id") %>' /></span></span>
</span>
<p><%# Eval("Message") %></p>
<span class="date float-right"><%# Eval("Comment_Date") %></span>
</div>
</div>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
This is the output:
Now, I would like to to show the nested replies to which user reply in a post it's shown only upto second level but I need a third as well as fourth level.
How is it possible?
In my Project, I have different types of Lighting categories. Each category has its ID. now In My UI, If I select particular category, its pics should be displayed in repeater. I don't know how to give ID in a href tag.
My HTML:
<ul class="filter text-center">
<li><a data-cat="all" href="#All" class="active">All</a></li>
<li><a data-cat="Dynamite" href="#DynamiteLounge">Dynamite Lounge</a></li>
<li><a data-cat="Morsel" href="#Morsel">The Morsel Restaurant & Banquet</a></li>
<li><a data-cat="Shagun" href="#Shagun">Shagun Hotel</a></li>
<li><a data-cat="Shops" href="#Shops">Shops</a></li>
<li><a data-cat="Bunglows" href="#Bunglows">Bunglows</a></li>
</ul>
<div class="bf-single-item" id="All">
<asp:PlaceHolder ID="plcAll" runat="server">
<asp:Repeater ID="rptrAll" runat="server">
<ItemTemplate>
<div class="bf-single-item">
<asp:Image ID="imgAll" runat="server" ImageUrl='<%# Eval("ImageAll")%>' />
<div class="caption">
<%--<div class="cap-in">
<h3>
CN Lighting</h3>
<div class="bflink-preview">
Zoom In
</div>--%>
</div>
</ItemTemplate>
</asp:Repeater>
</asp:PlaceHolder>
</div>
<div class="bf-single-item" id="DynamiteLounge">
<asp:PlaceHolder ID="plcDynamiteLounge" runat="server">
<asp:Repeater ID="rptrDynamiteLounge" runat="server">
<ItemTemplate>
<div class="bf-single-item">
<asp:Image ID="imgDynamiteLounge" runat="server" ImageUrl='<%# Eval("ImageDynamiteLounge") %>' />
<div class="caption">
<div class="cap-in">
<h3>
CN Lighting</h3>
<%--<div class="bflink-preview">
Zoom In
</div>--%>
</div>
</ItemTemplate>
</asp:Repeater>
</asp:PlaceHolder>
</div>
.
.
.
In this code, as you can see I have <a href in <li> and I have given href as a div Ids . See image. how to pass ID?
markup
<asp:LinkButton runat="server" Text="All" OnClick="LinkButton_Click"></asp:LinkButton>
protected void LinkButton_Click(object sender, EventArgs e)
{
var id = (sender as LinkButton).Attributes["data-cat"];
if(id == "All")
DoSomething();
}
your id cannot be retrieved like this in the code behind, but from ASP.NET 4 there is the Control.ClientID property that could help you.
Assuming instead that you wanted this client-side
document.getElementsByTagName('a').forEach(function(elem){
elem.addEventListened(click_handler);
});
function click_handler(){
var id = this.id;
if(id == 'All')
doSomething();
}
assuming that you know the Array.prototype.forEach method
I did a lot of research on this topic but I am not able to find any solution to this problem. I checked my page thoroughly but I am not able to fine "../" in my page. Need suggestions.My code on page is like this:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="PassRecovery.aspx.cs" Inherits="Login_PassRecovery" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<style>
input[type="text"], input[type="password"], input[type="email"], select, textarea {
height: 2em;
background:none;
border-radius:0px;
}
input[type="submit"], input[type="reset"], input[type="button"], .button {
padding: 16px;
line-height:0em;
height:2em;
border-radius:0px;
}
</style>
<div class="container">
<section id="main" class="container" style="padding-top:6em;">
<header>
<h2>Forgot your password?</h2>
<p>No problem, we can send it to you.</p>
</header>
<div class="row" style="width:65%;margin:0 auto;min-height:331px;">
<div class="12u">
<!-- Lists -->
<section class="box">
<div class="row collapse-at-2">
<div class="requiredFieldPrompt 3u" >
Your Email :
</div>
<div class="9u">
<div class="12u">
<asp:TextBox ID="txtEmailAddress" runat="server"></asp:TextBox></div>
<div class="12u"> <asp:RequiredFieldValidator ID="valEmail" runat="server" ErrorMessage="Please Enter your Email address"
ControlToValidate="txtEmailAddress" Display="Dynamic"></asp:RequiredFieldValidator></div>
<div class="12u"> <asp:RegularExpressionValidator ID="valEmailAddress" runat="server" ErrorMessage="Invalid Email Address"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="txtEmailAddress"
Display="Dynamic"></asp:RegularExpressionValidator></div>
<br />
</div>
</div>
<div class="12u" style="text-align:center;">
<asp:LinkButton ID="lnkGetUser" runat="server" CssClass="button" Text="Submit" OnClick="lnkGetUser_Click"></asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CssClass="button" href="Login.aspx" Text="Back" CausesValidation="false"
OnClick="lnkCancel_Click"></asp:LinkButton>
</div>
<div class="12u" style="text-align: center;">
<h4>
<asp:Label ID="lblMessage" runat="server"></asp:Label></h4>
</div>
<div class="12u" style="text-align:center;">
<asp:LinkButton ID="lnkContinue" runat="server" href="Login.aspx" Text="Sign in to your account"
CausesValidation="false" onclick="lnkContinue_Click"></asp:LinkButton>
</div>
</section>
</div>
</div>
</section>
</div>
</asp:Content>
Got the answer. Problem was with the master page. my masterpage was in the main directory and I was using ../ on it. Thx All. :)
How do I bind a string array(list of files in my case) to a variable in the item template?
Here is what I have so far but I am not sure what to do for the code behind itemdatabound.
I am trying to put each url in the <% Photo_URL %> variable.
Any help would be appreciated.
Thanks in advanced.
Page Code
<asp:Repeater id="unorderedList" runat="server" OnItemDataBound="unorderedList_ItemDataBound">
<HeaderTemplate>
<ul class="thumbs noscript">
</HeaderTemplate>
<ItemTemplate>
<li>
<a class="thumb" href='<%# Photo_URL %>'>
<img src='<%# Photo_URL %>'>
</a>
<div class="caption">
<div class="download">
<a href='<%# Photo_URL %>'>Download Original</a>
</div>
</div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
Code Behind
private void Page_Init(object sender, EventArgs e)
{
string[] photos = Directory.GetFiles(ImagesLocation);
unorderedList.DataSource = photos;
unorderedList.DataBind();
}
protected void unorderedList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//what goes here
}
<div class="download">
<a href='<%# Container.DataItem %>'>Download Original</a>
</div>
No need for the ItemDataBound event, you just need to use the <%# Container.DataItem %> syntax, like this:
<ItemTemplate>
<li>
<a class="thumb" href='<%# Photo_URL %>'>
<img src='<%# Container.DataItem %>'>
</a>
<div class="caption">
<div class="download">
<a href='<%# Container.DataItem %>'>Download Original</a>
</div>
</div>
</li>
You can use the Container.DataItem syntax:
<asp:Repeater id="unorderedList" runat="server" OnItemDataBound="unorderedList_ItemDataBound">
<HeaderTemplate>
<ul class="thumbs noscript">
</HeaderTemplate>
<ItemTemplate>
<li>
<a class="thumb" href='<%#Container.DataItem%>'>
<img src='<%#Container.DataItem%>'>
</a>
<div class="caption">
<div class="download">
<a href='<%#Container.DataItem%>'>Download Original</a>
</div>
</div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
You'll need to add a GridView in the ItemTemplate. Set it's DataSource to <%# Eval("string_list_name") %> where string_list_name is the variable name of your List of strings.