I'm new to ASP.NET techonology and I'm trying to use datatable Jquery with a repeater.
But it doesn't work with the value inside the table. It work with just the head (see below). These data come from a database.
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="Model2">
<HeaderTemplate>
<table id="table_id">
<thead>
<tr>
<th>Nom</th>
<th>ip</th>
<th>askit</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody>
<tr>
<td><%# Eval("Li_Id")%></td>
<td><%# Eval("Li_ip")%> </td>
<td><%# Eval("Li_nom_askit")%> </td>
</tr>
</tbody>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
And here it's what I get
Screen of what I have
So for example the line with id '594' is not in the datable that I have create.
I try to use a ListView but it doesn't work.
Does anybody know why ?
Thanks
You're creating a separate tbody around each row. Move the opening tbody tag to the end of the header template and the closing tbody tag to the beginning of the footer template.
(I'm assuming you're referring to the datatables.net jQuery plugin.)
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 have an <asp:Repeater> control that loads its data from a database.
To specify which column will be used where in the .aspx file, I use inside the Repeater's ItemTempate
<%# DataBinder.Eval(Container.DataItem, "column1")%>
Now when I need to make changes eg. I want another column instead of column1, I have to open Visual Studio, make the changes, publish the project again, and upload it to the server.
How can this control be more adjustable without having to change the source code each time?
Is there any other control that will do what I need better?
ASPX markup:
<table class="uk-table">
<thead>
<tr>
<th>User Name</th>
<th>Date 1</th>
<th>Date 2</th>
<th>State</th>
</tr>
</thead>
<tbody>
<asp:Repeater runat="server" ID="Repeater2">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<tr class="uk-table-middle">
<td><%# DataBinder.Eval(Container.DataItem,"column1")%></span></td>
<td><%# DataBinder.Eval(Container.DataItem,"column2")%></td>
<td><%# DataBinder.Eval(Container.DataItem,"column3")%> </td>
<td><%# DataBinder.Eval(Container.DataItem,"column4")%></span></td>
</tr>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
</tbody>
</table>
You need to define a condition like the following and save your condition either in the database or an XML file or even in the web.config (on yours) and do the following. Don't forget to retrieve your condition out of the repeater if you wanna apply to all rows:
<%
var myCondition = true; // whatever it could be...
%>
<asp:Repeater runat="server" ID="Repeater2">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<tr class="uk-table-middle">
<% if (mycondition){ %>
<td><%# DataBinder.Eval(Container.DataItem,"column1")%></span></td>
<td><%# DataBinder.Eval(Container.DataItem,"column2")%></td>
<% }else{ %>
<td><%# DataBinder.Eval(Container.DataItem,"column2")%></td>
<td><%# DataBinder.Eval(Container.DataItem,"column1")%></span></td>
<% } %>
<td><%# DataBinder.Eval(Container.DataItem,"column3")%> </td>
<td><%# DataBinder.Eval(Container.DataItem,"column4")%></span></td>
</tr>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater
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 html table in my ASPX page and would like to use it in code-behind for some processing. The table is shown as below:
<table class="hovertable" id="tblData">
<tr>
<th>ID:</th>
<td colspan="3" style="font-weight: bold">
<%= Eval("ID") %>
</td>
</tr>
<tr>
<th>Date:</th>
<td><%# Eval("Date", "{0:dd-MMM-yyyy}") %></td>
<th>Amount:</th>
<td><%# Eval("Amount", "{0:C}") %>
</tr>
</table>
However, when I add the runat="server" attribute to my table, I am produced with the following error:
CS1502: The best overloaded method match for 'System.Web.UI.HtmlControls.HtmlTableRowCollection.Add(System.Web.UI.HtmlControls.HtmlTableRow)' has some invalid arguments
Any ideas what may be wrong here? Am I missing out anything?
An html table (which is not a pure asp.net server control) can't contain asp.net server controls. Take a look at this answer:
http://forums.asp.net/t/1524580.aspx/1
In my opinion, you should ask yourself the following question?
Do i need to solve this client or server side?
if your answer is client, you should implement the update logic with Ajax, otherwise you could use the ASP.NET server control and implement it server side.
OK guys, I have solved this issue by myself. The problem causing it was because of a <td> not having the corresponding <tr> element.
It was something like below:
<table class="hovertable" id="tblData">
<tr>
<th>ID:</th>
<td colspan="3" style="font-weight: bold">
<%= Eval("ID") %>
</td>
</tr>
<tr>
<th>Date:</th>
<td><%# Eval("Date", "{0:dd-MMM-yyyy}") %></td>
<th>Amount:</th>
<td><%# Eval("Amount", "{0:C}") %>
</tr>
<td colspan='4'>
Some data....
</td>
</table>
I think you can use this for the same purpose
<asp:Table ID="Table1" runat="server">
</asp:Table>
What you are trying to do is adding runat="server" attribute to a HTML control
Try adding <asp:Labels> where you need to manipulate data.
<table>
<tr><td><asp:Label id="lblRow" runat="server" /></td></tr>
</table>
Table columns and rows cannot be accessed via code behind if you have runat="server" in the tag because they are pure html.
Another way is to use a StringBuilder to create the html table in the code-behind and and asp:LiteralControl to output the table.
Also if we remove the tbody element it will not throw error for td mismatch
Nikhil Mittal
Remove the below elements
<thead>
</thead>
<tbody>
</tbody>
Basically what i would like to do is have a button which is only created for entries that have been flagged in a separate table for sending. So for example if i edit a record, i flag this other table and would like a send button to appear next to that record via the repeater below - is this possible? Can i do a check by calling a method for example unsure :(
<asp:Repeater ID="DepartmentsList" runat="server">
<HeaderTemplate>
<table id="grouptable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Send</th>
<th>ID</th>
<th>Name</th>
<th>Last Modified</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<input type="checkbox" name="sendSelect[]" value="<%# Eval("Dept_ID") %>"</input></td>
<td><%# Eval("Dept_ID") %></td>
<td><%# Eval("DESC") %> </td>
<td><%# Eval("CHG_DATE") %></td>
<td><a class="btn btn-info" href="<%# Eval("gURL") %>"><i class="icon-pencil icon-white"></i> Edit</a><asp:Button ID="Button1" runat="server" Text="Send" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
You can do a check and inspect the current data record being bound to the repeater by using the DepartmentsList_OnItemDataBound event. It gives you all the power you need to dynamically change what's being bound and created in the repeater's item.