I've created a repeater on the front end, and I need to add multiple items, the second item is a string and this needs to be added to the image src, any thoughts?
<asp:Repeater runat="server" ID="WeatherForcastWeek" >
<ItemTemplate>
<td>
<asp:Label runat="server" ID="Day1" />
<asp:Image runat="server" ID="WeatherIcon" />
<asp:Label runat="server" ID="Min" />
<asp:Label runat="server" ID="Max" />
</td>
</ItemTemplate>
</asp:Repeater>
Below is the DataSource type
Tuple<string, string, double, double>
You need to use ImageUrl property and pass the value using the item binding syntax for ASP.NET WebForms <%# Item.Property #>
<asp:Repeater runat="server" ID="WeatherForcastWeek" ItemType="System.Tuple`4 [System.String,System.String,System.Double,System.Double]">
<ItemTemplate>
<td>
<asp:Label runat="server" ID="Day1" Text="<%# Item.Item1 %>" />
<asp:Image runat="server" ID="WeatherIcon" ImageUrl="<%# Item.Item2 %>" />
<asp:Label runat="server" ID="Min" Text="<%# Item.Item3 %>"/>
<asp:Label runat="server" ID="Max" Text="<%# Item.Item4 %>"/>
</td>
</ItemTemplate>
</asp:Repeater>
Related
<asp:DataList runat="server" DataSourceID="SqlDataSource1" ID="orderdatalist">
<ItemTemplate>
<table>
<td>
Order Number:
<br />
<asp:Label DataField="oID" Text='<%# Eval("oID") %>' ID="orderidlabel"></asp:Label>
</td>
<td>
USER ID:
<br />
<asp:Label runat="server" DatField="oUser_ID" Text='<%# Eval("oUser_ID") %>'></asp:Label>
</td>
<td>
ORDER STATUS:
<br />
<asp:Label runat="server" DataField="oDelivery_Status" Text='<%# Eval("oDelivery_Status") %>'></asp:Label>
</td>
</table>
</ItemTemplate>
</asp:DataList>
Above is the code for my asp page. I have a dropdown list with the following options: "Cancelled","Delivered" and "Order Placed". What I am trying to do here is to filter the datalist according to the dropdownlist value. E.g. If I click "Cancelled", the datalist will only show records which has "Cancelled" under the oDelivery_Mode field. Tried searching online but most are solutions to gridview etc. and none are about datalists. Any solutions?
This issue in not specific to GridView or DataList. All you need to do is set certain properties of SqlDataSource.
You can user FilterParameters and FilterExpression properties of SqlDataSource.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnctionString="<<connectionstring>>" SelectCommand="<<selectcommand>>" FilterExpression="oDelivery_Status = {0}">
<FilterParameters>
<asp:ControlParameter Name="OrderStatus" ControlID="<<dropdownlistid>>" PropertyName="SelectedValue" />
</FilterParameters>
<asp:SqlDataSource>
I am not sure of the connectionstring, select command and Id of the dropdownlist. So I have put the placeholders for them you need to use proper values there.
This should resolve your issue.
You need to use FilterParameters. Change the values according to your need.
<asp:DataList runat="server" DataSourceID="SqlDataSource1" ID="orderdatalist">
<ItemTemplate>
<table>
<td><%# Eval("OrderID") %>
</td>
<td><%# Eval("OrderName") %>
</td>
<td><%# Eval("OrderStatus") %>
</td>
</table>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource
ID="SqlDataSource1"
EnableCaching="true"
DataSourceMode="DataSet"
runat="server"
SelectCommand="select * from [Order]"
ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
FilterExpression="OrderStatus = '{0}'">
<FilterParameters>
<asp:ControlParameter
Name="orderparam"
ControlID="ddlOrderStatus"
PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="ddlOrderStatus" runat="server" OnSelectedIndexChanged="ddlOrderStatus_OnSelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Cancelled" Value="Cancelled"></asp:ListItem>
<asp:ListItem Text="Delivered" Value="Delivered"></asp:ListItem>
<asp:ListItem Text="OrderPlaced" Value="OrderPlaced"></asp:ListItem>
</asp:DropDownList>
protected void ddlOrderStatus_OnSelectedIndexChanged(object sender, EventArgs e)
{
orderdatalist.DataBind();
}
I am working on my class project where I created an image gallery using listview.
The Designing is below:
<asp:ListView ID="lvPresent" runat="server" DataSourceID="SqlDataSource1">
<LayoutTemplate>
<table>
<tr>
<td></td>
</tr>
</table>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<td>
<asp:HyperLink ID="HyperLink1" runat="server">
<asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />
</asp:HyperLink>
</td>
</ItemTemplate>
</asp:ListView>
How can I send the url of the selected image from one .aspx page to another anothe ?
To send URL to another page you can use QueryString.
Modify your HyperLink and add NavigateUrl
NavigateUrl='<%#"yourNextPageName.aspx?imgURL="+ Eval("url")%>'
just replace you code:-
<asp:HyperLink ID="HyperLink1" runat="server">
<asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />
</asp:HyperLink>
with
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#"yourNextPageName.aspx?imgURL="+ Eval("url")%>'>
<asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />
</asp:HyperLink>
Add image URL as query string ,
NavigateUrl ='yourNextPageName.aspx?imgURL=<%# Eval("url")%>'
in HyperLink
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl ='yourNextPageName.aspx?imgURL=<%# Eval("url")%>' >
<asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />
</asp:HyperLink>
In destination page , get your image url as string _imgURL =Request.QueryString["imgURL"];
I am creating a website and am facing the following problem. I have 2 ListViews.
The first ListView is inside a user control called Sidebar.ascx:
<asp:ListView ID="sidebarListView" runat="server" DataKeyNames="Id" DataSourceID="SqlDataSourceSidebar">
<ItemTemplate>
<div class="sidebarItem" runat="server">
<div>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</div>
</div>
</ItemTemplate>
<LayoutTemplate>
<div class="sidebarMain">
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" />
</div>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSourceSidebar" runat="server" ConnectionString="<%$ ConnectionStrings:TudengiDBConnectionString %>" SelectCommand="SELECT [Id], [Name] FROM [Faculties] ORDER BY [Name]"></asp:SqlDataSource>
It has to display only the name.
The second listview is inside my Default.aspx
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ListView ID="RecentItemsListView" runat="server" DataSourceID="SqlDataSource1"
GroupItemCount="3">
<LayoutTemplate>
<div class="recentItemsMain">
<asp:PlaceHolder runat="server" ID="groupPlaceHolder" />
</div>
<asp:DataPager ClientIDMode="Static" ID="DataPager1" runat="server" PageSize="9">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<GroupTemplate>
<div class="recentItems">
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" />
</div>
</GroupTemplate>
<ItemTemplate>
<div class="recentItem" runat="server">
<div>
<asp:Image ID="PictureThumb" runat="server" ImageUrl='<%#CreateThumbnail((string)Eval("Picture"),130,130) %>' />
</div>
<asp:Label ID="AuthorLabel" runat="server" Text='<%# Eval("Author") %>' />
<div>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</div>
</div>
</ItemTemplate>
<GroupSeparatorTemplate>
<div class="groupSeparator">
</div>
</GroupSeparatorTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TudengiDBConnectionString %>" SelectCommand="SELECT [Id], [Name], [Faculty_Id], [User_Id], [Author], [Picture], [Location] FROM [Books] ORDER BY [DateAdded] DESC">
What I need is for the ListView in Default.aspx to display the data without a WHERE clause, but when an item is clicked in the Sidebar user control I need to update the Default.aspx ListView to display only the data where the [Faculty_Id] = the ID of the ListView item in the user control.
How can I get the database ID of the ListView object when I can only display the NAME field? Do I have to display the ID as well and then hide the column from users?
What is the correct way to solve a situation like this?
Thanks for helping
<asp:ListView ID="sidebarListView" runat="server" DataKeyNames="Id" DataSourceID="SqlDataSourceSidebar" OnItemCommand="sidebarListView_ItemCommand">
<ItemTemplate>
<div class="sidebarItem" runat="server">
<div>
<asp:LinkButton ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' CommandName="Select" CommandArgument='<%# Eval("Id") %>' />
</div>
</div>
</ItemTemplate>
This is what I ended up with.
Add a hidden-field to your item-template to hold the database ID.
<ItemTemplate>
<asp:HiddenField ID="hdnFacultyID" runat="server" Value='<%# Eval("FacultyID") %>' />
<div class="recentItem" runat="server">
...
</div>
</ItemTemplate>
In the appropriate ListView handlers, you can access the database ID something like this.
((HiddenField)e.item.FindControl("hdnFacultyID")).Value
What you can do is to add an attribute to the NameLabel control.
Call it for example myID:
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' myID='<%# Eval("ID") %>'/>
then access that attribute from your code to get your ID:
string ID = NameLabel.Attributes["myID"];
I am working on a real estate website and I am using a datalist (ASP.NET / C#) to show listing, my next step which i can't figure out how to do it, is if I click on the link 'edit', Select information for that specific house and show it in the Edit.aspx and each field of the datalist is shown in a textbox.
My database is pretty easy with just 4 fields : IDhouse, Price, Bedroom, ImgHouse.
Please if someone can help me I will appreciate it so much, thank you.
Code:
<asp:DataList ID="DataList1" runat="server" DataKeyField="IDhouse"
DataSourceID="SqlDataSource1"/>
<ItemStyle ForeColor="#000066" />
<ItemTemplate>
<table>
<tr>
<td class="style2">
Price : <asp:Label ID="Label1" runat="server" Text='<%# Eval("Price", "{0:C}") %>' /><br />
Beds : <asp:Label ID="Label2" runat="server" Text='<%# Eval("Bedroom") %>' /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<asp:HyperLink ID="HyperLink2" runat="server">Delete</asp:HyperLink>
<asp:HyperLink ID="HyperLink1" runat="server">Edite</asp:HyperLink>
</td>
<td class="style1">
<asp:Image ID="Image1" runat="server" Height="201px" Width="331px"
ImageUrl='<%# "~/DisplayImg.ashx?IDhouse="+ Eval("IDhouse") %>'/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
Replace
<asp:HyperLink ID="HyperLink1" runat="server">Edite</asp:HyperLink>
with
Edit
and on the Edit.aspx page, load the required data based on the IDhouse value obtained from the querystring
I have a custom search control on my page (asp.net) which contains a textbox and a repeater for displaying results.
The repeater is populated with a callback as the user types ... nice and simple callback.
...
When a search result is selected the repeater fires off a postback and the itemcommand event is raised (as expected) ... and this event adds a child repeater to itself and binds a child list to the current item.
My problem is that I don't want my parent repeater to fire off a full postback because the page is quite time consuming to render.
I tried putting the control / just the outer repeater in to an ajax update panel control but it appears to still fire a ful postback.
Can anyone shed any light on how I might tell a repeater to fire its item command event in a callback instead of a postback?
I'm guessing this involves a load of manual wiring for my repeater item controls but i'm hoping theres a control somewhere that handles all that for me :)
EDIT : Sample of my situation ....
<asp:UpdatePanel ... >
<asp:Repeater ...>
<itemTemplate> <asp:LinkButton ... CommandArg='<%= Eval("ID") %>' CommandName="select" /> </itemTemplate>
</asp:Repeater>
</asp:UpdatePanel>
So my question is ...
How do i tell the repeater "fire this link buttons onclick as a callback instead of a postback"
the process of wrapping up the repeater in an update panel doesn't help because the ID of the link button is dynamic and therefore I cannot (not inline anyway) add a trigger for the link button.
If i manually add a trigger to the panel in the repeaters onitembound event i get an exception from .Net sayingt he callback reference is invalid ... i guess this is because im trying to attach a callback trigger to a control that is already handling a postback event or something setup by the repeater ...
EDIT 2 : Sample of the scenario faced here
essentially because this control X number of times on the page virtually everything has to be dynamic.
The control implements ICallbackHandler and the search bx code (not included below) fires off an ajax call onkeyup when the user types in company names (so it works a bit like google).
I was hoping that when a user clicked on a company name from the list it would ajax call back / partial postback to recover the sub list of branches thus preventing the full page flicker you get with a full postback.
Then a user would select a branch and it would do a full postback which would result in several server actions taking place.
This works fine as is ... its just not the cleanest user experience.
<div id='<%= this.UniqueID + "Results" %>' class="results">
<asp:Repeater ID="ui_lstCompanies" runat="server" onitemcommand="ui_lstCompanies_ItemCommand">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<asp:Panel ID="item" runat="server">
<li>
<asp:LinkButton ID="ui_btnSelectCompany" runat="server" CommandName="Select" Text='<%# Eval("Name") %>' />
</li>
</asp:Panel>
<asp:Panel ID="selectedItem" runat="server" Visible="false">
<li>
<hr /><h4><%# Eval("Name") %></h4>
<asp:Repeater ID="ui_lstBranches" runat="server" onitemcommand="ui_lstBranches_ItemCommand" >
<HeaderTemplate>
<table style="border-collapse:collapse;">
<tr><th> </th><th>Branch Name</th><th>Branch Address</th><th>Tel</th><th>Fax</th><th>Email</th></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> </td>
<td><asp:LinkButton ID="ui_btnSelectBranch1" runat="server" CommandArgument='<%# Eval("ID") %>' CommandName="Select" Text='<%# Eval("Name") %>' /></td>
<td><asp:LinkButton ID="ui_btnSelectBranch2" runat="server" CommandArgument='<%# Eval("ID") %>' CommandName="Select" Text='<%# Eval("Address") %>' /></td></td>
<td><asp:LinkButton ID="ui_btnSelectBranch3" runat="server" CommandArgument='<%# Eval("ID") %>' CommandName="Select" Text='<%# Eval("Telephone1") %>' /></td></td>
<td><asp:LinkButton ID="ui_btnSelectBranch4" runat="server" CommandArgument='<%# Eval("ID") %>' CommandName="Select" Text='<%# Eval("Fax") %>' /></td></td>
<td><asp:LinkButton ID="ui_btnSelectBranch5" runat="server" CommandArgument='<%# Eval("ID") %>' CommandName="Select" Text='<%# Eval("Email") %>' /></td></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<hr />
</li>
</asp:Panel>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
I had a similar problem as you did. If you replace the linkbuttons with regular asp:button and continue to use the repeater's itemcommand event as you were, it will work. Why? I don't know. However, it works. It may not look good with your design, but it triggers the asynch postback that you desired.
<asp:Repeater runat="server" ID="rpt1">
</asp:Repeater>
<asp:UpdatePanel runat="server" ID="up1">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rpt1"/>
</Triggers>
<ContentTemplate>
<asp:Repeater runat="server" ID="rpt2">
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
This should then perform an async call to all commands from rpt1.
Just Replace these repeater control's with yours
EDIT:
I've basically created a mockup of your code with different fields etc. I assume the code below is what you tried and it was not working? If so then I've got no idea why it's not working on your side as it is on myne, there must be some slight difference somewhere that we're not picking up.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<div id='<%= this.UniqueID + "Results" %>' class="results">
<asp:Repeater ID="ui_lstCompanies" runat="server" OnItemCommand="ui_lstCompanies_ItemCommand">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<asp:Panel ID="item" runat="server">
<li>
<asp:LinkButton ID="ui_btnSelectCompany" runat="server" CommandName="Select" Text='<%# Eval("Name") %>' />
</li>
</asp:Panel>
<asp:Panel ID="selectedItem" runat="server" Visible="false">
<li>
<hr />
<h4>
<%# Eval("Name") %></h4>
<asp:Repeater ID="ui_lstBranches" runat="server" OnItemCommand="ui_lstBranches_ItemCommand">
<HeaderTemplate>
<table style="border-collapse: collapse;">
<tr>
<th>
</th>
<th>
Branch Name
</th>
<th>
Branch Address
</th>
<th>
Tel
</th>
<th>
Fax
</th>
<th>
Email
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
</td>
<td>
<asp:LinkButton ID="ui_btnSelectBranch1" runat="server" CommandArgument='<%# Eval("ID") %>'
CommandName="Select" Text='<%# Eval("Name") %>' />
</td>
<td>
<asp:LinkButton ID="ui_btnSelectBranch2" runat="server" CommandArgument='<%# Eval("ID") %>'
CommandName="Select" Text='<%# Eval("Address") %>' />
</td>
</td>
<td>
<asp:LinkButton ID="ui_btnSelectBranch3" runat="server" CommandArgument='<%# Eval("ID") %>'
CommandName="Select" Text='<%# Eval("Telephone1") %>' />
</td>
</td>
<td>
<asp:LinkButton ID="ui_btnSelectBranch4" runat="server" CommandArgument='<%# Eval("ID") %>'
CommandName="Select" Text='<%# Eval("Fax") %>' />
</td>
</td>
<td>
<asp:LinkButton ID="ui_btnSelectBranch5" runat="server" CommandArgument='<%# Eval("ID") %>'
CommandName="Select" Text='<%# Eval("Email") %>' />
</td>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<hr />
</li>
</asp:Panel>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
</ContentTemplate>
</asp:UpdatePanel>