I tried to using Datalist and Something goes wrong I cant solve it !
On the Output... why the extra row is created after each row??
what's my fault?
Look at my codes :
<asp:DataList ID="DataList1" runat="server" DataKeyField="Id" DataSourceID="SqlDataSource1" Width="233px">
<HeaderTemplate>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>InTheater</th>
<th>Spam</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>`
I just dealt with this problem myself. I solved it by removing the <tr> in the template. So instead of
<tr>
<th>Id</th>
<th>Title</th>
<th>InTheater</th>
<th>Spam</th>
</tr>
I used
<th>Id</th>
<th>Title</th>
<th>InTheater</th>
<th>Spam</th>
I don't know why it adds the extra rows but this was the solution I found.
Posting for others looking for the answer.
Related
I have a page with a listview and there is some problem with it, however instead of getting an error, when I run it I get a 404 resource not found error. If I remove the offending listview and run then it runs fine, so it is not an issue with it not looking in the right place for the page etc.
How can I find out what the error is with the listview, at the moment I'm getting no information about it, it even renders correctly in design view.
Many thanks
For info the code is below, however I need to know how to debug it as this has happened lots of times before.
If I remove this listview the page works..
<asp:ListView ID="lvPerformanceKPIs" runat="server"
OnItemDataBound="lvPerformanceKPIs_ItemDataBound" DataKeyNames="PerformanceMeasureID"
OnItemCommand="lvPerformanceKPIs_ItemCommand" ItemPlaceholderID="itemPlaceholder"
>
<LayoutTemplate>
<table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
<th width="5%" class="Actions" >
Actions
</th>
<th width="2%" > 
</th>
<th width="5%">
ID
</th>
<th width="28%">
Group
</th>
<th width="40%">
Indicator
</th>
<th width="20%">
Threshold
</th>
</tr>
</table>
<div runat="server" id="itemPlaceHolder">
</div>
</LayoutTemplate>
<ItemTemplate>
<div id="Div1" class="SUBDIV" runat="server">
<table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
<td width="5%" class="Actions">
<%--<img id="btnEdit" style="cursor: pointer;" alt="Edit" title="Edit this record" src="images/edit.png" width="15px"
onclick="CRMEdit(this);"/>
<asp:ImageButton ID="btnDelete" runat="server" title="Delete this record" src="images/delete.png" width="15px"
OnclientClick="return confirm('Are you sure you want to delete this record?')"
CommandName="cmdDelete" CommandArgument=<%#Eval("PerformanceMeasureID") %> /> --%>
</td>
<td width="2%">
<div class="btncolexp collapse" title="Expand to reveal/add files">
</div>
</td>
<!-- id columns to get values then will be hidden with jquery -->
<td class="hidCol">
<span id="itemServiceSpecID"><%#Eval("ServiceSpecID")%></span>
</td>
<td class="hidCol">
<span id="itemPerfSortOrder"><%#Eval("PerfSortOrder")%></span>
</td>
<td class="hidCol">
<span id="itemPerfType"><%#Eval("PerfType")%></span>
</td>
<td class="hidCol">
<span id="itemPerfFrequency"><%#Eval("PerfFrequency")%></span>
</td>
<td width="5%">
<span id="itemPerformanceMeasureID"><%#Eval("PerformanceMeasureID")%></span> 
</td>
<td width="28%">
<span id="itemPerfGroup"><%#Eval("PerfGroup")%></span> 
</td>
<td width="40%">
<span id="itemPerfMeasure"><%#Eval("PerfMeasure")%></span> 
</td>
<td width="20%">
<span id="itemPerfThresholdText"><%#Eval("PerfThresholdText")%></span> 
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:ListView>
i wonder if those images are properly commented-out in the item template. make sure there is no conflict between the comment tags (<%-- --%>) and the data binding tags.
also, the CommandArgument needs to be quoted:
CommandArgument='<%#Eval("PerformanceMeasureID") %>'
this is my code to view products as list view inside each item in list view i want to view list of items how can i do this? i can not understand the concept of the eval function and i want to know if i can pass to it list items from code behind without data Bind or it basically depends on data-bind ?
<asp:ListView ID="mylistView" runat="server" GroupItemCount="3">
<EmptyDataTemplate>
<table id="Table2" runat="server">
<tr>
<td>
No data was returned.
</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td id="Td3" runat="server" />
</EmptyItemTemplate>
<GroupTemplate>
<tr id="itemPlaceholderContainer" runat="server">
<td id="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<table border="0" width="300" style="display: inline-block; background-color: Lime;">
<tr>
<td>
 
</td>
<td>
<a href='ContactUs.aspx'>
<image src='productsImg/<%# Eval("Pic_Path") %>' width="100" height="75" border="0">
</a> 
</td>
<td>
<a><b style="text-decoration: underline;">
<%# Eval("MenuName") %></b> </a>
<br />
want to view here list of items
I
</td>
</tr>
</table>
</ItemTemplate>
<LayoutTemplate>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="groupPlaceholderContainer" runat="server">
<tr id="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td2" runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
this is code behind...
dataSource.ConnectionString = connetionString;
dataSource.SelectCommand = "SELECT * FROM tbl_WebMenu where MenuID like'3_';";
mylistView.DataSource = dataSource;
mylistView.DataBind();
thanks in advance.
Eval is used to bind to an UI control that is supposedly read only. it can be used to set any type of property of control.
The complete syntax is "Databinder.Eval", it has to be used in conjunction with databind.
Look at this example.
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblRead" runat="server" Text='<%# Eval("FieldName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
you can even set a property of control using eval. it provides flexibility.
But there is a downside of eval as it uses reflection to evaluate the expression.
Read more here http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx#remarksToggle
I recently did a nested repeater according to this tutorial. The same thing
http://www.codeproject.com/Articles/6140/A-quick-guide-to-using-nested-repeaters-in-ASP-NET
But I added a jQuery accordion just like this example:
http://www.snyderplace.com/demos/accordion.html
Everything is good, but I realized some UI issues. I mean for example if one of my nested repeaters has 100 records and another has just 1 record, for this second with just 1 record, it has a blank space reserved as it had 100 records also. Someone knows how to fit the height each nested repeater to its elements?
<div id="accordion">
<asp:Repeater ID="summary" runat="server" OnItemDataBound="summary_ItemDataBound">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div>
Id:<asp:Literal ID="litCategory" runat="server" />
</div>
<div>
<asp:Repeater ID="detail" runat="server" OnItemDataBound="detail_ItemDataBound">
<HeaderTemplate>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Literal ID="litID" runat="server" /></td>
<td><asp:Literal ID="litName" runat="server" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</div>
I got it! I found this solution!
$(function () {
$("#accordion").accordion({
collapsible: true,
heightStyle: "content"
});
});
I need to specify that to attributes and that's it!
I realize this is a strange/simple question. I have HTML—tables and rows—that make up a grid. I need the resulting grid to look exactly like the HTML does, with data pulled from a DataTable.
How should I go about doing that? If I replace the HTML with a GridView the result will look different from what I need it to look like. Do I create a custom grid class that spits out tables and rows?
To clarify: I've been given an HTML grid...
<div>
<table>
<tr>
<td>row 1 col 1</td>
<td>row 1 col 2</td>
</tr>
<tr>
<td>row 2 col 1</td>
<td>row 2 col 2</td>
</tr>
</table>
</div>
...which I now need to populate with data from a table, and preserve the original HTML.
If you want to use ASP.Net databinding capabilities, go with a Repeater. The markup will look something like this:
<table>
<thead>
<tr>
<th>Heading</th>
</tr>
</thead>
<tbody>
<asp:Repeater runat="server">
<ItemTemplate>
<tr>
<td><%# Eval("SomeFieldName") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
You can also build the markup manually in the code-behind by instantiating table/row/cell objects and adding them to the controls collection of the page, control, or parent container control. This tends to be time-consuming but it's a valid option in some cases, such as when you wish to have highly dynamic content that isn't easy to express in a Repeater.
A third option is to mix server markup with client markup, e.g.
<table>
<thead>
<tr>
<th>Heading</th>
</tr>
</thead>
<tbody>
<% foreach( var obj in someCollection ){ %>
<tr>
<td><%= obj.Property %></td>
</tr>
<% } %>
</tbody>
</table>
The last option is quite similar (albeit more verbose) to Razor syntax used in ASP.Net MVC views.
I think your best bet for that would be a repeater. Link below.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater(v=vs.100).aspx
Another option would be to use a ListView with your HTML table setup as the LayoutTemplate.
quick example:
<asp:ListView ID="MyListView" runat="server">
<LayoutTemplate>
<table id="Table1" cellpadding="1" width="100%" runat="server">
<tr id="Tr1" runat="server">
<th id="Th1" style="font-weight: bold; text-align: left" runat="server">
Header1
</th>
<th id="Th2" style="font-weight: bold; text-align: left" runat="server">
Header2
</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server">
<td style="text-align: left">
<%# Eval("Field1")%>
</td>
<td style="text-align: left">
<%# Eval("Field2")%>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I know this is a pretty strange question but I need to know which item was clicked before the click event fires on the repeater.
This will tell me that it was the repeater that is doing the post back, but not which item was clicked:
Request.Params["__EVENTTARGET"].ToString()
How do I find out which repeater item was clicked?
If it helps, here is the markup for the repeater in full.
<asp:Repeater ID="ResultsRepeater" runat="server">
<HeaderTemplate>
<table cellpadding="3" cellspacing="0" width="360">
<tr bgcolor="#d5d5e6">
<th width="10">
</th>
<th>
Content Type
</th>
<th>
Items Found
</th>
<th>
Results
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="#efefef">
<td width="10">
<img src="http://www.exactmobile.co.za/images/li_x.gif">
</td>
<td>
<%# DataBinder.Eval(Container, "DataItem.Name") %>
</td>
<td align="center">
<b class="brown">
<%# DataBinder.Eval(Container, "DataItem.Count") %></b>
</td>
<td align="center">
<asp:LinkButton runat="server" CommandName="Results">Show <font class="red">»</font></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#ffffff">
<td width="10">
<img src="http://www.exactmobile.co.za/images/li_x.gif">
</td>
<td>
<%# DataBinder.Eval(Container, "DataItem.Name") %>
</td>
<td align="center">
<b class="brown">
<%# DataBinder.Eval(Container, "DataItem.Count") %></b>
</td>
<td align="center">
<asp:LinkButton runat="server" CommandName="Results">Show <font class="red">»</font></asp:LinkButton>
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Did you try setting up event handlers for each of your link button controls? If not, doing that might as well take you exactly to respective event handler automatically.
Also see if this helps ASP.NET - Add Event Handler to LinkButton inside of Repeater in a RenderContent call
Worked around the issue by just using normal anchors in the template and setting their hrefs to the actual pages in the controls Pre_Render method.