I would like to know, why I can't reference "asp:Image" (Image1) control in my code, but I can reference datalist control (DataList1) which contains asp:Image. Here is my code:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="imageHolder">
<asp:DataList ID="DataList1" runat="server" RepeatColumns="4" Width="100%">
<ItemTemplate>
<asp:Image ID="Image1" OnDataBinding="DataList1_DataBinding" Width="80%" Height="100px"
CssClass="datalistImages" runat="server" ImageUrl='<%# "http://mywebsite.com/" + Eval("url") %>' />
</ItemTemplate>
</asp:DataList>
</asp:Content>
And I'm 100% sure I'm working in the correct class. Any suggestions?
Because it's in the item collection.
If you want to reach that image control at real time you have to use ItemCreated or ItemDataBound events.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.items%28v=vs.110%29.aspx
Datalist events.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist_events%28v=vs.110%29.aspx
Related
I have the following situation:
<asp:Repeater ID="myRepeater" runat="server">
<ItemTemplate>
<asp:ImageButton OnClick="imgSearchResult_Click" BackColor="#333333" ID="imgSearchResult" height="32" width="32" runat="server" ToolTip='<%# Eval("ToolTip") %>' ImageUrl='<%# Eval("ImageUrl") %>'/>
<asp:Label ID="labValue" Text='<%# Eval("Text") %>' runat="server" Width="32" />
</ItemTemplate>
</asp:Repeater>
The Repeater contains ImageButton and Label objects. If I only use one object, I can add them from codebehind through the binding:
Repeater.DataSource = imageList;
Repeater.DataBind();
OR
Repeater.DataSource = labelList;
Repeater.DataBind();
How can I add both to one Repeater?
If you need them in one Repeater, they -are- related in that "view" (loosely used term) of the data. So why not make that view into an explicit object that contains both the image and the label? Either named, or anonymous:
return Enumerable.Zip(imageList, labellist, (image, label) => new {image, label})
Alternatively, you can just pass the images and query for the labels by index:
<asp:Repeater ID="myRepeater" runat="server">
<ItemTemplate>
<asp:Label ID="labValue" Text='<%# GetLabelText(Container.ItemIndex) %>' runat="server" Width="32" />
</ItemTemplate>
</asp:Repeater>
This requires a public GetLabelText(index) method and probably extra state in your code behind to make the ImageList available to that method. Not very nice, but it gets the job done.
I have the following List:
private List<System.Web.UI.WebControls.Image> _searchResultList = new List<System.Web.UI.WebControls.Image>();
This List may contain several Images with different URLs.
I have the following Repeater:
<asp:Panel ID="SearchPanel" runat="server" ScrollBars="Vertical">
<asp:Repeater ID="Repeater" runat="server">
<ItemTemplate>
<asp:Image height="32" width="32" runat="server"/>
</ItemTemplate>
</asp:Repeater>
</asp:Panel>
Using DataSource to display the images doesn't seem to work.
Repeater.DataSource = _searchResultList;
Repeater.DataBind();
What am I doing wrong?
The _searchResultList is not a list of strings so you can't use ImageURL='<%Container.DataItem.ToString()%>'. Because _searchResultList is a list of images you should bind the ImageUrl property. This should works fine for you:
<asp:Repeater ID="Repeater" runat="server">
<ItemTemplate>
<asp:Image ID="Image1" height="32" width="32" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' />
</ItemTemplate>
</asp:Repeater>
In this example Container.DataItem refers to an Image control. This is why we used Eval("ImageUrl") to get the ImageUrl property of each Image control.
<asp:Panel ID="SearchPanel" runat="server" crollBars="Vertical">
<asp:Repeater ID="Repeater" runat="server">
<ItemTemplate>
<asp:Image height="32" width="32" runat="server" ImageURL='<%Container.DataItem.ToString()%>'/>// changes here
</ ItemTemplate>
</asp:Repeater>
</asp:Panel>
I have 2 updatepanels in a webforms page with 2 nested Repeater controls. In the second (inner Repeater control) I have a LinkButton to do some events and calling the click event through the OnItemCommand method of the second Repeater.
This is my Example Asp.Net page
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
<asp:Repeater ID="Repeater2" runat="server" OnItemCommand="Repeater2_ItemCommand">
<ItemTemplate>
<asp:Label ID="lblInsertedDate" class="text-muted" runat="server" Text=' <%# string.Format("{0: hh:mm tt}", Eval("Date")) %>'></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:LinkButton ID="lnkFollow" runat="server" Text="Follow" CommandArgument='<%# Eval("BrokerId") %>' CommandName="Follow"></asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
When I click on the LinkButton, I can see the contents of the outer Repeater also gets XHRed when I inspect through browser's network Tab.
I don't want to update the contents of outer updatepanel when I click on the linkbutton inside. I want to change only text of the linkbutton with some server side function, so that the content download will be gets reduced.
Similar Question asked https://stackoverflow.com/questions/29543567/updatepanel-with-updatemode-conditional-and-childrenastriggers-false-refreshed-b with no answer for it.
I tried to set UpdateMode="Conditional" and ClientAsTriggers as false to both the inner and outer updatepanels. However it's not working. Using .net version 4.51. Any workaround for this?
I am trying to get an image to display on a page using a Hyperlink inside a datalist.However, the image will not display, I just get the correct number of boxes with what I call the no image picture. I know that it is retrieving the filepath correctly. The tooltip shows the correct path, it is the exact path going into a repeater that works, but does not display the image. Any help would be greatly appreciated.
<%# Control Language="C#" AutoEventWireup="true" CodeFile="HomePagePhotosList.ascx.cs" Inherits="UserControls_HomePagePhotosList" %>
<asp:DataList ID="list" runat="server" Width="1000px" CssClass="EventsList"
RepeatDirection="Horizontal">
<HeaderStyle CssClass="DepartmentsListHead" />
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink
ID="HyperLink1"
Runat="server"
ImageUrl='<%#System.String.Format("Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'
NavigateUrl='<%# Link.ToEditMinutesAdmin(Eval("ImageID").ToString())%>'
ToolTip='<%# System.String.Format("Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:DataList>
In order to fix this problem I had to change the
ImageUrl='<%#System.String.Format("Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'
To
ImageUrl='<%#System.String.Format("~/Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'
in my web page i want to place the ajax Dropdownexteder. but it is not working fine this is my code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="lbldrp" runat ="Server" Text ="MyDropDown"></asp:Label>
<asp:Panel ID="Mypanel" runat ="Server" >
<asp:LinkButton ID ="linkmsn" runat ="Server" Text ="www.stackoverflow.com"></asp:LinkButton><br />
<asp:LinkButton ID ="linkgoogle" runat ="Server" Text ="www.google.com"></asp:LinkButton>
</asp:Panel>
<cc1:DropDownExtender ID="DropDownExtender1" TargetControlID ="lbldrp" DropDownControlID ="Mypanel" runat="server" >
</cc1:DropDownExtender>
<cc1:AnimationExtender ID="AnimationExtender1" TargetControlID ="Mypanel" runat="server">
<Animations>
<OnShow>
<HideAction Visible="true" />
</OnShow>
<OnHide>
<HideAction Visible="false" />
</OnHide>
</Animations>
</cc1:AnimationExtender>
</form>
it is giving some error like
"Animation on TargetControlID="Mypanel" uses property AjaxControlToolkit.AnimationExtender.OnShow that does not exist or cannot be set"
help me thank you.
Hai Sasidhar OnShow and Onhide are not valid properties of ajaxcontroltoolkit:animationExtender, instead u can use OnMouseOver for OnShow and OnMouseOut for OnHide
Look at this http://www.c-sharpcorner.com/UploadFile/raj1979/AnimationExtender01242008065540AM/AnimationExtender.aspx
or
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Animation/Animation.aspx and check its properties