For the solution, I cannot use any postback methods, because this is all working through ajax. The solution need to be implemented in the asp.net code.
I have a List<WebPage> that contains a list of Links (List<Link>) and I need for all the links to bind repetitive information such as page title, id, url. Here is my current repeater.
<div id="result">
<asp:Repeater runat="server" id="results">
<Itemtemplate>
<asp:Repeater runat="server" datasource='<%# Eval("Links") %>'>
<Itemtemplate>
<tr class="gradeX odd">
<td><%# Eval("Id") %></td> //property of WebPage (part of results repeater)
<td><%# Eval("Title") %></td> //property of WebPage (part of results repeater)
<td><%# Eval("Url") %></td> //property of WebPage (part of results repeater)
<td><%# Eval("URL") %></td>//Property of Link
<td><%# Eval("URLType") %></td> //Property of Link
<td><%# Eval("URLState") %></td> //Property of Link
</tr>
</Itemtemplate>
</asp:Repeater>
</Itemtemplate>
</asp:Repeater>
</div>
of course this doesnt work, how can i do this?
Thanks for your help!
Try this:
DataBinder.Eval(((RepeaterItem)Container.Parent.Parent).DataItem,
"URL")
The key is to work your way back up to the parent repeater item, and then use the eval method.
Not of course actually.
I have almost the same, but into inner repeater datasource is set as DataSource='<%# GetLinks(Container.DataItem) %>'
where GetLinks returns casted enumerable of Links
Related
When I click the button in the repeater, I want to get the data about the relevant row. But without the page postback. I want to use UpdatePanel but I couldn't figure out how to do it. Can you help me?
Here are sample codes:
<asp:Repeater ID="rptCariler" runat="server">
<ItemTemplate>
<tr>
<td><%#Eval("CariKodu") %></td>
<td><%#Eval("CariUnvani") %></td>
<td><%#Eval("CariGrubu") %></td>
<td><%#Eval("AdSoyad") %></td>
<td><%#Eval("Borc") %></td>
<td><%#Eval("Alacak") %></td>
<td><%#Eval("Bakiye") %></td>
<td class="xsml">
<asp:LinkButton ID="lbGetValue" runat="server" OnClick="GetValue"><span><i class="fas fa-trash-alt"></i></span></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
Well, you don't note if you need the info client side, or server side?
I mean, if you drop the whole repeater into a update panel then you don't get a full page post back.
You would (should) then tag the controls as server side. Assuming the whole repeater inside of a update panel, say like this:
<asp:Repeater ID="r2" runat="server">
<ItemTemplate>
<table id="mytable" runat="server">
<tr>
<td><%#Eval("HotelName") %></td>
<td><%#Eval("City") %></td>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
</td>
</tr>
</table>
<br />
</ItemTemplate>
</asp:Repeater>
So now the code behind can work like this:
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton mybutton = (LinkButton)sender;
RepeaterItem repItem = (RepeaterItem)mybutton.Parent.Parent.Parent.Parent ;
HtmlTableRow rRow = (HtmlTableRow)mybutton.Parent.Parent;
Debug.WriteLine("Repeater index click = " + repItem.ItemIndex);
Debug.WriteLine(rRow.Cells[0].InnerText);
Debug.WriteLine(rRow.Cells[1].InnerText);
}
This much comes down to if you want code behind here.
I mean, I would use a gridview, or listview if this is a table of data - you have better options for a "grid" of data in place of a repeater.
I'm trying to use an ASP:DataList to display data from my data source. Everything works ok, except I'm getting ASP to add an extra column when there isn't one. The Header Template and Item Template are shown below
<asp:DataList runat="server" ID="xTable" DataKeyField="PK_PurchaseID" DataSourceID="SqlDataSource1" RepeatLayout="table" CssClass="table">
<HeaderTemplate>
<td>PuchaseID</td>
<td>Last Name</td>
<td>First name</td>
<td>Address1</td>
<td>Email Sent</td>
</HeaderTemplate>
<ItemTemplate>
<td><%# Eval("PK_PurchaseID") %></td>
<td><%# Eval("LastName") %></td>
<td><%# Eval("FirstName") %></td>
<td><%# Eval("Address1") %></td>
<td><%# Eval("[Email Sent]") %></td>
</ItemTemplate>
</asp:DataList>
And is the the DOM object created. I would expect 5 columns in the table yet it is rendered as 6
<table class="table" id="xTable" style="border-collapse: collapse;" cellspacing="0">
<tbody><tr>
<td>
<td>PuchaseID</td>
<td>Last Name</td>
<td>First name</td>
<td>Address1</td>
<td>Email Sent</td>
</tr><tr>
<td>
<td>3</td>
<td>Albdddim</td>
<td>James </td>
<td>1----63rd Ave.</td>
<td>true</td>
</tr>
I can not figure you why an initial column is being created. I changed the CSS, even removed it and still the same result. I have verified the SQL only returns the 5 columns (even if it returned more or less that shouldn't make a difference)
Thanks Chris
The HeaderTemplate and ItemTemplate are meant to be td elements so it automatically creates the td. If you do something like this
<asp:DataList runat="server" ID="xTable" DataKeyField="PK_PurchaseID" DataSourceID="SqlDataSource1" RepeatLayout="table" CssClass="table">
<HeaderTemplate>
PuchaseID
<td>Last Name</td>
<td>First name</td>
<td>Address1</td>
<td>Email Sent</td>
</HeaderTemplate>
<ItemTemplate>
<%# Eval("PK_PurchaseID") %>
<td><%# Eval("LastName") %></td>
<td><%# Eval("FirstName") %></td>
<td><%# Eval("Address1") %></td>
<td><%# Eval("[Email Sent]") %></td>
</ItemTemplate>
</asp:DataList>
It would put the purchase ID in the first td that is created and then fill out the table like you want.
I create table inside a repeater
and the data appears correctly, it will be two records looks like in the image below.
what i want: how to make accordion when user clicks on the deposit number(Example 16), new table will appear and contain data.
this is the repeater the first repeater code:
<asp:Repeater ID="rptDep" runat="server" >
<HeaderTemplate>
<table class="table table-hover table-striped table-condensed table-bordered table-responsive">
<tr>
<th>Deposit No.</th>
<th>Custom Declaration No.</th>
<th>Category</th>
<th>Location</th>
<th>Goods Description</th>
<th>Units Balance</th>
<th>WT Balance</th>
<th>Goods Balance Amount(LC)</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%#Eval("depNo") %></td>
<td><%#Eval("customDec") %></td>
<td><%#Eval("category") %></td>
<td><%#Eval("location") %></td>
<td><%#Eval("goodDesc") %></td>
<td><%#Eval("unitsBal") %></td>
<td><%#Eval("wtBal") %></td>
<td><%#Eval("lcBal") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
I know that it will be a second repeater, but how to implement that, or how to use foreach statement?
I got it, I found the solution by reading this article:
Implement Nested Repeater (Repeater inside Repeater) with example in ASP.Net using C# and VB.Net
I have a nested repeater inside of another repeater like this:
<table>
<asp:Repeater ID="RepeaterOuter" runat="server">
<ItemTemplate>
<tr>
<td><asp:TextBox Text='<%# Eval("Author") %>' /></td>
</tr>
<asp:Repeater ID="RepeaterInner" runat="server">
<ItemTemplate>
<tr>
<td><asp:TextBox Text='<%# Eval("Book") %>' /></td>
<td><asp:TextBox Text='<%# Eval("PublishDate") %>' /></td>
<td><asp:TextBox Text='<%# Eval("Pages") %>' /></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</table>
However, when I try to access the child repeater, RepeaterInner, from my code behind file, it says that it does not exist in the current context. The parent repeater, RepeaterOuter, does however.
I am trying to set up a loop, to loop through my TextBox's in the child repeater but it won't let me access it:
//does not work
foreach (RepeaterItem item in RepeaterInner.Items)
{
txtBook= (TextBox)item.FindControl("Book");
txtPublishDate = (TextBox)item.FindControl("PublishDate");
txtPages = (TextBox)item.FindControl("Pages");
// do something....
}
Thank you.
At first, I very much doubt this inner repeater even exists before the outer one is data bound. So make sure you are accessing inner repeater at a right time.
At second, controls that are in templates are not visible like this on the page. To get the control in the template you need to use FindControl. Also note that FindControl works only with direct children, so your code should look something like this:
var innerRepeater = RepeaterOuter.Items[0].FindControl("RepeaterInner") as Repeater;
I know how you can set an tag's url attribute programmatically in c#, but it seems when I try to access the image element inside of a tag I cannot access it.
The is residing in the <AlternatingItemTemplate>.
NOTE: I am only having this issue inside the <AlternatingItemTemplate>
Now the ListView tag is also databound.(this is probably why I cannot access, because it isn't guaranteed that it will even exist perhaps).
How can I get around this so that I can display my images programmatically or is there a better solution?
Here's the source:
<asp:ListView ID="ListView_Comments" runat="server"
DataKeyNames="ReviewID,ProductID,Rating" DataSourceID="EDS_CommentsList">
<ItemTemplate>
<tr style="background-color:#EDECB3;color: #000000;"> <td><%# Eval("CustomerName") %></td>
<td> <img src='Styles/Images/ReviewRating_d<%# Eval("Rating") %>.gif' alt="">
<br />
</td>
<td> <%# Eval("Comments") %>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color:#F8F8F8;"> <td><%# Eval("CustomerName") %></td>
<td>
<img id="rateImage" src="" alt="" runat="server" />
......
Should be able to access it in the codebehind in the OnItemDatabound Event. There u can check to see if its an alternating item or not then use FindControl and u should have access to it.
Or, if your image is stored in your datasource y not just set the src using <%# Eval %>