what is the difference between item template and the layout template. in layout template only we have information about the designing? or any thing else. i am unable to understand the item template.. please explain..!
In addition to this one i have query in project like this
SELECT TOP (1) ProductName, UnitPrice FROM Products ORDER BY NEWID()
here NEWID() means what? is it predefined function related to sqlserver? there is no any newid() function in my project which was downloaded. if it is predefined function then what it can do?
Thank you
The main layout of a ListView control is created by defining a LayoutTemplate. The LayoutTemplate will include controls that acts as a placeholder for the data like Table, Panel, Label or HTML controls like table, div, or span elements that have a runat attribute set to "server".
Item template is the main template which will show the data bounded to the ListView in a repeated manner. This template typically contains controls that are data-bound to data columns or other individual data elements. These two templates are mandatory.
GroupTemplate will be used to group the items. The EditItemtemplate, SelectedItemTemplate, InsertItemTemplate are shown at that particular operation like insert, edit, select. ItemSeparatorTemplate, GroupSeparatorTemplate are used to separate the individual items and group Items Separately.
Here this makes difference ItemPlaceholderID="itemPlaceholder"
<asp:ListView runat="server" ID="ListView1" ItemPlaceholderID="itemPlaceholder">
<LayoutTemplate>
<table border="0" cellpadding="1">
<tr style="background-color:#E5E5FE">
<th align="left"><asp:LinkButton ID="lnkId" runat="server">Id</asp:LinkButton></th>
<th align="left"><asp:LinkButton ID="lnkName" runat="server">Name</asp:LinkButton></th>
<th align="left"><asp:LinkButton ID="lnkType" runat="server">Type</asp:LinkButton></th>
<th></th>
</tr>
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><asp:Label runat="server" ID="lblId"><%#Eval("ID") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblName"><%#Eval("FirstName")+"
"+Eval("LastName") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblType"><%#Eval("Type") %></asp:Label></td>
<td></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color:#EFEFEF">
<td><asp:Label runat="server" ID="lblId"><%#Eval("ID") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblName"><%#Eval("FirstName")+" "+
Eval("LastName") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblType"><%#Eval("Type") %></asp:Label></td>
<td></td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
Reference links: reference site, code project reference
It looks like you're using the ListView control.
The ItemTemplate property only applies to the data item bound to the control. The LayoutTempate allows you to define the layout for everything else.
Let's say your wanted to render your data using a . your LayoutTemplate would contain your table definition with a single, empty row with ID "itemPlaceHolder"
<tr id="itemPlaceHolder" runat="server" />
Your item template would then define how your s should be rendered.
Related
I'm using bootstrap to collapse and expand a table, which is working fine but I'm using classes instead of IDs. With this, expanding one row expands all the rows rather than just that one. My question is how does my data-target point at a nested repeater id? The transactionCollapse ID is unable to be targeted directly and I've tried doing <%=transactionGroupedList.FindControl("transactionCollapse")%> but it threw an error.
<tbody>
<asp:Repeater runat="server" ID="transactionGroupedList" OnItemDataBound="TransactionGroupedDataList_ItemDataBound">
<ItemTemplate>
<tr>
<!-- This line should target the transactionCollapse ID below instead of the class -->
<td data-toggle="collapse" data-target=".transactionCollapse">
<span id="transactionGroupCollapseIcon" runat="server" class="fonticon-down-arrow"></span>
<custom:Label runat="server" ID="transactionActivityDataColumnLabel"></custom:Label>
</td>
<td>
<custom:Label runat="server" ID="transactionDateDataColumnLabel">
</custom:Label>
</td>
<td>
<custom:Label runat="server" ID="transactionNumberDataColumnLabel">
</custom:Label>
</td>
<td>
<custom:Label runat="server" ID="transactionAmountDataColumnLabel">
</custom:Label>
</td>
<td>
<custom:Label runat="server" ID="transactionStatusDataColumnLabel">
</custom:Label>
</td>
</tr>
<asp:Repeater runat="server" ID="transactionDetailList" OnItemDataBound="TransactionDetailsDataList_ItemDataBound">
<ItemTemplate>
<tr id="transactionCollapse" runat="server" class="collapse transactionCollapse">
<td colspan="2">
<custom:Label runat="server" ID="transactionDetail">
</custom:Label>
</td>
<td>
<custom:Label runat="server" ID="transactionDetailTransactionNumber">
</custom:Label>
</td>
<td>
<custom:Label runat="server" ID="transactionDetailAmount">
</custom:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</tbody>
The Online Payment row is what collapses/expands the Posting - and MP Payment rows below. This user only has one Online Payment, but many users will have multiple.
You have a couple of problems. First of all when using FindControl inside a Repeater/GridView etc is index based. So you need to use FindControl on the correct Item.
transactionGroupedList[i].FindControl("transactionCollapse")
However the above will still not work because transactionCollapse is in a nested Repeater that needs to be found first and then access the correct Item Index.
transactionGroupedList.Items[0].FindControl("transactionDetailList").Items[0]...
But this will also not work since FindControl does not know that transactionDetailList is a Repeater with index based Items. So you need to cast the nested Repeater first before you can access it's items. So it becomes this
<%= ((Repeater)transactionGroupedList.Items[i].FindControl("transactionDetailList")).Items[i].FindControl("transactionCollapse").ClientID %>
I have a structure that looks like this:
Strategies 1..n Objectives
Objective 1..n Initiatives
Each are in a different table and linked through foreign keys.
I want to be able to nest my results in a few list view (3 to be exact).
When I try to create a dynamic ID for my nested ListView, the code doesn't compile anymore.
<asp:ListView ID="ObjectivesListView" runat="server">
<LayoutTemplate>
<table style="width:100%">
<tr style="align-content:flex-start">
<th>#</th>
...
</tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr >
<td onclick='toggleDiv("obj",<%#Eval("ID") %>)'>
<%# Container.DataItemIndex + 1 %>
</td>
...
</tr>
<tr id='obj<%#Eval("ID") %>' class="hide">
<td colspan="7">Another item
<!-- New list view with the initiative for Objective x -->
<asp:ListView runat="server" ID="initiativeListView">
<LayoutTemplate></LayoutTemplate>
<ItemTemplate></ItemTemplate>
</asp:ListView>
<!-- New list view with the initiative for Objective x -->
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I have tried to create a dynamic ID for my second listView by doing ID="initiativeListView<%#Eval(ID)%>"> and that causes the error.
I am also running in a sharepoint environment and limited to the ASP classes. I wanted to preload and display it when the user clicks on the row.
Any Ideas?
In your child control instead of Eval(ID) you need to use
Eval(Container.Parent, "DataItem.ID")%
in first child and
Eval(Container.Parent.Parent, "DataItem.ID")%
in the second child of your nested controls
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 "";
}
In my masterpage I have links for users also the authorization is different like admin and regular user.
links under each other and I can hide the hyperlinks depending on authorization status but the problem is i.e when I have 3 links the second link for the admin the link will hide when the user is regular and the link place empty like 123 1 3.
So I have an idea using table each link in one tr but I can`t hide td or tr because Visible is not in properties.
any help?
thank you
According to how to hide a having asp.net control:
you can give ID either to the TD or TR to which you want to hide/show
with the runat="server" and also you can take that tr/td inside the
div tag and give id to that div tag and also runat=server attribute
and after that you can pro grammatically hide/show that div.
like
<pre>
<tr id="trhide" runat="server"> </tr>
</pre>
in code behind write
trhide.visible=true/false
In the master page VB code behind add a public procedure: Then call the public set from your aspx page.
'======================================================================================================
'Set Tab No invisible
'======================================================================================================
Public Sub setTabNumberLabel(visible As Int16)
If visible = 0 Then
td_page.Visible = False
Else
td_page.Visible = True
End If
End Sub
The master aspx would be:
<table style="width:100%">
<!--<tr style="background-color:#565656;">-->
<tr>
<td style="width:15%;text-align:left;vertical-align:bottom;padding-left:20px;">Stategic Energy Assessment ( <asp:Label ID="lbl_year_ended" runat="server" /> )</td>
<td style="text-align:center;vertical-align:bottom;"><asp:Label ID="lbl_utility_name_and_id" runat="server" /></td>
<td id="td_page" runat="server" style="width:15%;text-align:right;vertical-align:bottom;padding-right:20px;">Tab No: <asp:Label ID="lbl_page" runat="server" /></td>
</tr>
<tr><td colspan="3" style="vertical-align:central"><hr /></td></tr>
<tr>
<td style="width:15%;text-align:left;vertical-align:central">
<asp:Label ID="lbl_print_version" runat="server" Text="View Printable Vision" Visible="false" />
</td>
<td style="font-size:larger; font-weight:bold; text-align:center; text-transform:capitalize;vertical-align:central">
<asp:Label ID="lbl_schedule_name" runat="server" />
</td>
<td style="width:15%;text-align:right;vertical-align:central;padding-right:20px;">
<asp:LinkButton ID="btn_footnotes" runat="server" Visible="false">Footnotes</asp:LinkButton>
</td>
</tr>
<%--<tr><td colspan="3" style="vertical-align:central" class="auto-style1"></td></tr>--%>
<tr><td colspan="3" style="vertical-align:central; padding-right:20%;padding-left:20%; ">
<i><asp:Label ID="lbl_headnotes" runat="server" Text="" /></i></td></tr>
<tr><td colspan="3" style="vertical-align:central"><hr /></td></tr>
</table>
The other answer is correct and works fine. Just adding complete piece of code.
It's quite amusing that you don't need to add runat=server for a table but you can still hide tr for that table using runat attribute.
<table>
<tr>
<td>aa</td><td>bb</td>
</tr>
<tr id="trHide1" runat="server">
<td>aa</td><td>bb</td>
</tr>
<tr id="trHide2" runat="server">
<td>aa</td><td>bb</td>
</tr>
<tr>
<td>aa</td><td>bb</td>
</tr>
</table>
Now just set properties in codebehind (hiding the tr)
trHide1.Visible = false;
trHide2.Visible = false;
What I'd like to do is create a second row that spans the others within a GridView. The idea is that it is data within the GridViewRow, say a long varchar() in col 4. But when translating to HTML, how would I put that in a second row?
<table>
<tr>
<td></td>
<th>ru sure?</th>
<th>date</th>
<th>category</th>
</tr>
<tr>
<td rowspan="2">edit</td>
<td>yes</td>
<td>"12/31/2009"</td>
<td>website feedback</td>
</tr>
<tr>
<td colspan="3"><textarea rows="3" cols="50"></textarea></td>
</tr>
</table>
I can take care of the cell output, but I don't know how to terminate one row and begin another. Logically, it still represents one row of data.
One techniquehack that I've used is to have the last regular column of the GridView be a TemplateField, and then put the extra row in there. For example, something like this:
<asp:GridView runat="server">
<Columns>
<asp:BoundField/>
<asp:BoundField/>
<asp:BoundField/>
<asp:TemplateField>
<ItemTemplate>
<%#Eval("category")%>
</td></tr>
<tr><td colspan="3">
<textarea rows="3" cols="50"></textarea>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Have you looked at the ListView control? It allows for some very complex layouts.
http://msdn.microsoft.com/en-us/library/bb398790.aspx