It shows error "Non-invocable member 'System.Web.UI.WebControls.RepeaterItem.DataItem' cannot be used like a method.
for the <%# Container.DataItem("CostPageDescription")%>
my code below,
<td> Cost Page Description</td>
<td> Vendor Name</td>
<td> Bill Type</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%# Container.DataItem("CostPageDescription")%></td>
<td> <%# Container.DataItem("VendorName")%> </td>
<td> <%# Container.DataItem("BillType") %> </td>
</tr>
<tr>
USE LIKE THIS
<td> <%# eval("CostPageDescription")%></td>
and at one place u left it blank, so make that correct
Use this:
<%# Eval("CostPageDescription") %>
or this:
<%# DataBinder.Eval(Container.DataItem, "CostPageDescription") %>
First one is just a simplification of the second.
Related
I have bound a DataSet to a ListView. In the ListView ItemTemplate, if a row value is empty, I do not want it, or the <td> element it is enclosed in to display.
In my code, the first row value will display. However, when I try to use the If statement on the second <td> element, that will not display.
<asp:ListView ID="ListView1" runat="server" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"> </asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"> </asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<%# Eval("textItem1") %>
</td>
<% if (!String.IsNullOrEmpty(textItem2){ %>
<td>
<%# Eval("textItem2") %>
</td>
<%} %>
</ItemTemplate>
</asp:ListView>
That If statement works in an aspx page if its NOT being used in a ListView, Repeater, or GridView (or does it?). I need to be able to check if that string row value is empty and not display it or the <td> element it is enclosed in. I am not against a solution that uses code-behind. Is there another way to do this then my attempt?
I used a pretty simple method solution..
In the above code, I swapped out this...
<% if (!String.IsNullOrEmpty(textItem2){ %>
<td>
<%# Eval("textItem2") %>
</td>
<%} %>
For this...
<%# writeText(Eval("textItem2").ToString())%>
And placed this method in the code behind...
public string writeText(string kiss)
{
if (!String.IsNullOrEmpty(kiss))
return "<td> " + kiss + "</td>";
else
return null;
}
how do I use a within an UserControl?
I always get the error, that the CheckBox should be placed within a FormTag (with runat=server), which is still existing on the MasterPage and it is not allowed to have two of them ...
Code of UserControl:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ctrlOrderEmailsDialog.ascx.cs" Inherits="WebClient.Controls.ctrlOrderEmailsDialog" %>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<div id="OrderEmailDialog" runat="server">
<table id="OrderEmailDialogTable">
<tbody>
<tr>
<th>Nr.</th>
<td>
<asp:Label ID="labelId" runat="server"></asp:Label></td>
</tr>
<tr>
<th>ReturnReceipt:</th>
<td>
<%--<telerik:RadButton ID="checkboxReturnReceipt" runat="server" ToggleType="CustomToggle" ButtonType="ToggleButton" AutoPostBack="false">
<ToggleStates>
<telerik:RadButtonToggleState Text="UnChecked" PrimaryIconCssClass="rbToggleCheckbox"></telerik:RadButtonToggleState>
<telerik:RadButtonToggleState Text="Filled" PrimaryIconCssClass="rbToggleCheckboxFilled"
Selected="true"></telerik:RadButtonToggleState>
<telerik:RadButtonToggleState Text="Checked" PrimaryIconCssClass="rbToggleCheckboxChecked"></telerik:RadButtonToggleState>
</ToggleStates>
</telerik:RadButton>--%>
<asp:CheckBox ID="checkboxReturnReceipt" runat="server" />
</td>
</tr>
<tr>
<th>Mailtext:</th>
<td>
<asp:Label ID="OrderEmailText" runat="server">
</asp:Label>
</td>
</tr>
</tbody>
</table>
</div>
Form Tag (already existing within the SiteMaster page):
<form id="MainForm" runat="server">
System.Web.HttpException:
"The control ctrlOrderEmailsDialog_checkboxReturnReceipt type CheckBox must be positioned in a form tag with runat = server." which is existing ...
Can you guys give me a small hint?
Thank you.
//SiL
I have records from database separated by department, I want to tile them horizontally inside different tables (for each department). Here is what I tried (This does not work)
Aspx
<asp:ListView ID="lvUnderwriting" GroupItemCount="6" runat="server" GroupPlaceholderID="grpPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table>
<asp:PlaceHolder ID="grpPlaceHolder1" runat="server" ></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<span><b><%# Eval("gensubbusiclass") %></b></span>
<table>
<tr>
<th>Role Name:</th>
<th>Pending Tasks:</th>
<th>On Leave:</th>
</tr>
<tr>
<asp:PlaceHolder ID="itemPlaceHolder1" runat="server"></asp:PlaceHolder>
</tr>
</table>
</GroupTemplate>
<ItemTemplate>
<tr>
<td><span> <%#Eval("RoleName") %></span></td>
<td><span><%# Eval("Count") %></span></td>
<td><span><%# Eval("OnLeave") %></span></td>
</tr>
</ItemTemplate>
</asp:ListView>
Database rows
My current results. For some reason the second department is divided into two tables. Also how do I tile them horizontally?
Okay what I got was that ListView cannot display master detail records out of the box. Here is what I tried to get it working for me. The trick was to dynamically add a new row to the table if the header databound item was changed, the database records need to be sorted in advance to get this working. Referenced from here using Asp.net 3.5 ListView 4 Guys from Rolla
Aspx
<asp:ListView ID="lvUnderwriting" runat="server" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table border="1" cellpadding="4px">
<tr>
<th>Role Name:</th>
<th>Assigned:</th>
<th>On Leave:</th>
</tr>
<tr>
<asp:PlaceHolder ID="itemPlaceHolder1" runat="server" />
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<%# AddGroupUnderwriting() %>
<td><%# Eval("RoleName") %></td>
<td><%# Eval("Count") %></td>
<td><%# Eval("OnLeave") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
C#
// Add group row to underwriting grid
private string prevUWBusinessClass = "";
public string AddGroupUnderwriting()
{
string currentUWBusinessClass = Eval("gensubbusiclass").ToString();
if (currentUWBusinessClass != prevUWBusinessClass)
{
prevUWBusinessClass = currentUWBusinessClass;
return string.Format(#"<tr><td colspan=""3""><h3>Department: {0}</h3></td></tr>", currentUWBusinessClass);
}
else
return "";
}
I'm trying to figure out how to use a temporary variable (created from a loop) to show/hide a button.
I have tabular data and some action buttons to the side of them. I need to be able to turn buttons off and on based on the state of that data.
f.IsFoo is a boolean
<table stuff here>
<% foreach (Foo f in listOfFoos) { %>
<tr>
<td>
<%= Fubar(f)%>
</td>
<td>
<%= Fubar1(f) %>
</td>
<td>
<%= Fubar2(f)%>
</td>
<td>
<%= Fubar3(f)%>
</td>
<td>
<%= Fuba4(f)%>
</td>
<td>
<%= Fubar5(f)%>
</td>
<td>
<asp:Button Text="Load" runat="server" OnClick="FooBar" Visible='<%= f.IsFoo%>'/>
</td>
</tr>
<%}%>
I'm pretty new to aspx and it's syntax and online searches have just confused me more.
Personally I tend to put logic like this in the code behind file - however I believe the code below should work,
I added an ID to your button - and I also removed the visibility property - I'm then referencing the button, by its ID - and setting its visibility equal to that of the f.IsFoo property
Possibly try this here:
<% btnFoo.Visible = f.IsFoo; %>
<asp:Button ID="btnFoo" Text="Load" runat="server" OnClick="FooBar" />
I have a datagrid where some of the text needs to span multiple columns. Here is an example of what I need.
Row # Image Name Price Date
1 xxx My Name $99 1/1/2009
xxx
xxx Long description goes here
2 xxx name 2 $99 1/1/2009
xxx
xxx Another long description
Is something like this possible in Asp.Net using a datagrid? Any suggestions on how to do this?
You might find it easier to use an ASP.Net Repeater instead, and have multiple rows per DataItem. That way, you get complete control over the layout.
It's technically possible to use the ASP.Net GridView to do it, but I suspect this wouldn't be the most elegant solution here. The GridView (and Datagrid) were designed out of the box for one row per DataItem.
Here is some sample ASP.Net containing a Repeater that illustrates an approach that might work for you:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<tr>
<th>
Col 1
</th>
<th>
Col 2
</th>
<th>
Col 3
</th>
</tr>
<ItemTemplate>
<tr>
<td>
<%# Eval("Field1") %>
</td>
<td>
<%# Eval("Field2") %>
</td>
<td>
<%# Eval("Field3") %>
</td>
</tr>
<tr>
<td>
<%# Eval("Field4") %>
</td>
<td colspan="2">
<%# Eval("Field5") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Note that the ItemTemplate contains two HTML table rows, the second of which contains a td with a colspan of 2.
Hope that helps a little.
Do you have to use a DataGrid?, I would suggest the ListView control. It has all the functionality you need and uses templates for full UI control.