I have a Datalist. Following is the structure of the ItemTemplate:
<ItemTemplate>
<div id="driversGrid" runat="server" style="width:3500px;" >
<table cellpadding="0" cellspacing="0" border="0" width="3500px">
<tr>
<td id="Td1" runat="server" style="visibility:hidden;">
<asp:Label ID="lblID" runat="server" BackColor="White" Font-Bold="true" Text='<%# Eval("ID") %>' /><br />
</td>
<td id="title" style="width:90px;text-align:center;">
<asp:Label ID="lblTitle" runat="server" BackColor="White" Font-Bold="true" Text='<%# Eval("Name") %>' /><br />
</td>
<td id="am0900" runat="server" style="width:90px;"> </td>
<td id="am0915" runat="server" style="width:90px;"> </td>
<td id="am0930" runat="server" style="width:90px;"> </td>
<td id="am0945" runat="server" style="width:90px;"> </td>
<td id="am1000" runat="server" style="width:90px;"> </td>
<td id="am1015" runat="server" style="width:90px;"> </td>
<td id="am1030" runat="server" style="width:90px;"> </td>
<td id="am1045" runat="server" style="width:90px;"> </td>
<td id="am1100" runat="server" style="width:90px;"> </td>
</tr>
</table>
</div>
</ItemTemplate>
Now, at the itemdatabound event, I fetch multiple time (data) from the database in form 10:25 AM.
I manipulate each data and convert it to am1030 (similar to one of the td ID in itemTemplate). Now I want to check each td in ItemTemplate and compare the lblID (i.e. the staff ID) to the ID in my variable and then compare the tdID to the manipulated data. If they match change the background color of the td.
In short, I want to check that if the lblID is 3 then get the td with ID am1030 and change the background color.
Needs to be done in C#.net.
Use a foreach loop to iterate through the e.Item.Controls collection, like this -
foreach (Control c in e.Item.Controls)
{
//if c is HtmlCell, then check the ID and change the color.
}
Related
Respected Viewers I need only a specific column does not repeat again and again in Gridview I attache a screenshot in you can see room charges repeat 3 times but I need to this repeat only one time and then its charges and date are shown in simple language it is a heading Please review
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Width="100%" BorderWidth="0px" BorderStyle="None" OnRowDataBound="GridView1_RowDataBound" ShowFooter="true" OnDataBound="GridView1_DataBound">
<Columns>
<asp:TemplateField HeaderStyle-BorderStyle="None" ItemStyle-BorderStyle="None" FooterStyle-BorderStyle="None" >
<ItemTemplate>
<table style="width:100%;font-size:12px;text-align:left">
<tr>
<td colspan="5">
<table style="width:100%;font-size:16px; font-weight:bold; font-family:Cambria, Cochin, Georgia, Times, Times New Roman, serif;text-align:left;margin-bottom:10px">
<tr><td><u> <asp:Label ID="lblprintheading" runat="server" Text='<%#Eval("Headingname")%>' ></asp:Label></u>
</td></tr>
</table>
</td>
</tr>
<tr>
<td style="width:10%;">
<asp:Label ID="lblservicedate" runat="server" Text='<%#Eval("Date")%>'></asp:Label>
</td> <td style="width:50%;">
<asp:Label ID="lblparticular" runat="server" Text='<%#Eval("Servicename")%>'></asp:Label> (<asp:Label ID="Label22" runat="server" Text='<%#Eval("doctorname")%>'></asp:Label>)
</td>
<td style="width:10%;">
<asp:Label ID="lblrate" runat="server" Text='<%#Eval("Rate")%>'></asp:Label>
</td>
<td style="width:10%;">
<asp:Label ID="lblnos" runat="server" Text='<%#Eval("Qty")%>'></asp:Label>
</td>
<td style="width:20%;">
<asp:Label ID="lblprice" runat="server" Text='<%#Eval("Nettotal")%>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate >
<table style="width:100%;text-align:center; border:0px none">
<tr>
<td colspan="5" style="text-align:right;padding-right:50px"> ..................................................................................</td>
</tr>
<tr>
<td style="width:10%;">
</td> <td style="width:50%;">
</td>
<td style="width:10%;">
</td>
<td style="width:10%; font-size:18px; font-weight:bold;">
Total:
</td>
<td style="width:20%;">
<asp:Label ID="Label18" runat="server" Text='<%#Eval("Nettotal")%>'></asp:Label>
</td>
</tr>
</table>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
https://i.stack.imgur.com/6Rl6K.png
You can use nested grid view. Which will give you perfect result as you want.
I have built a ASP.NET Application and use two divs and a ListView. My ListView get Data from a Database and if I have to much Rows a I get a overflow but I want then a Scrollbar for this ListView.
My Site:
My Site if I have to much rows :(
My Site with a Scrollbar that I want!
My Code:
<asp:Content ID="Content2" ContentPlaceHolderID="lw_content" runat="server">
<div class="userlist">
<div class="liste">
<asp:ListView runat="server" ID="myListView">
<LayoutTemplate>
<table id="UserList" border="0" cellpadding="0" cellspacing="0">
<tr style="background-color:#ccdaeb">
<th align="left">
<asp:Label ID="header_name" runat="server" Text="Name"></asp:Label></th>
<th align="left">
<asp:Label ID="header_firma" runat="server" Text="Firma"></asp:Label></th>
<th align="left">
<asp:Label ID="header_von" runat="server" Text="gültig ab"></asp:Label></th>
<th align="left">
<asp:Label ID="header_bis" runat="server" Text="gültig bis"></asp:Label></th>
<th align="left">
<asp:Label ID="header_ersteller" runat="server" Text="erstellt von"></asp:Label></th>
</tr>
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td align="left"><asp:Label ID="lblname" Text='<%# Eval("GanzerName") %>' runat="server" /></td>
<td align="left"><asp:Label ID="lblfirma" Text='<%# Eval("Firma") %>' runat="server" /></td>
<td align="left"><asp:Label ID="lblvon" Text='<%# Eval("GültigVon") %>' runat="server" /></td>
<td align="left"><asp:Label ID="lblbis" Text='<%# Eval("GültigBis") %>' runat="server" /></td>
<td align="left"><asp:Label ID="lblersteler" Text='<%# Eval("Ersteller") %>' runat="server" /></td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<h4>Es wurden keine Einträge gefunden</h4><br/>
<asp:Button runat="server" ID="btnAnlegen" Text="Benutzer Anlegen"/>
</EmptyDataTemplate>
<AlternatingItemTemplate>
<tr>
<td align="left"><asp:Label ID="lblname" Text='<%# Eval("GanzerName") %>' runat="server" /></td>
<td align="left"><asp:Label ID="lblfirma" Text='<%# Eval("Firma") %>' runat="server" /></td>
<td align="left"><asp:Label ID="lblvon" Text='<%# Eval("GültigVon") %>' runat="server" /></td>
<td align="left"><asp:Label ID="lblbis" Text='<%# Eval("GültigBis") %>' runat="server" /></td>
<td align="left"><asp:Label ID="lblersteler" Text='<%# Eval("Ersteller") %>' runat="server" /></td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
</div>
</div>
</asp:Content>
You can fix the hsight if liste div and set overflow to visible or what ever suits you. Height must be less then the height taken by data in side div to see the scroll bar.
Change
<div class="liste">
to
<div class="liste" style="height:300px; overflow:scroll">
or
<div class="liste" style="height:300px; overflow:visible">
Try setting the overflow to scroll:
<div class="liste" style="height:200px; overflow:scroll;">
I'm working on the following
var result =
from ap in db.Appraisals
join at in db.AppraisalTypes
on ap.AppraisalType_ID equals at.AppraisalType_ID
join w in db.Workers
on ap.Worker_ID equals w.Worker_ID
where ap.Worker_ID == WorkerID
&& ap.DateDue != null
&& ap.DateCompleted == null
select new
{
ap.Worker_ID,
ap.Appraisal_ID,
at.Description,
ap.DateDue,
ap.DateCompleted,
CompletedBy = from ap2 in db.Appraisals
join w2 in db.Workers
on ap2.CompletedBy equals w2.Worker_ID
select new
{
name = w2.Surname + ", " + w2.FirstName
}
};
As you can probably see I am using two worker objects, one being the worker that is having their annual/interim employment appraisal and the other object is their line manager.
This select is used to bind a summary list view control but on the CompletedBy column I am trying to assign will always have the most up to date entry as being null then historic data will be populated with the line managers name when an appraisal has been completed. I have done a quick search on this question and there are many posts w/answers but I'm not very experienced as a developer and looking for a simple answer. My other concern is that I am trying to assign a column with something that I know will always have a null value in the list.
Although the compiler recognises this as being syntactically correct, on the bind my label text property has the following...
System.Collections.Generic.List`1[<>f__AnonymousType9`1[System.String]]
I am just looking to any possible caveats I am building here and to fill in the huge gaps to my very limited knowledge of LINQ.
<asp:ListView ID="lvwProbations" runat="server"
OnSelectedIndexChanged="lvwProbations_SelectedIndexChanged"
OnPagePropertiesChanged="lvwProbations_PagePropertiesChanged"
OnPagePropertiesChanging="lvwProbations_PagePropertiesChanging"
DataKeyNames="Worker_ID,Appraisal_ID">
<ItemTemplate>
<tr class="tableItemStyle"
onmouseover="this.style.backgroundColor='Silver'"
onmouseout="this.style.backgroundColor='#EAFFFF'">
<td>
<asp:Label ID="lblWorkerID" runat="server"
Text='<%# Bind("Worker_ID") %>' Visible="false" />
</td>
<td>
<asp:Label ID="lblProbation" runat="server" Width="200"
Text='<%# Bind("Description") %>' />
</td>
<td align="center">
<asp:Label ID="lblDateDue" runat="server" Width="100"
Text='<%# Bind("DateDue", "{0:d}") %>' />
</td>
<td align="center">
<asp:Label ID="lblDateCompleted" runat="server" Width="100"
Text='<%# Bind("DateCompleted") %>' />
</td>
<td align="center">
<asp:Label ID="lblCompletedBy" runat="server" Width="100"
Text='<%# Bind("CompletedBy") %>' />
</td>
<td>
<asp:ImageButton ID="btnSelect" runat="server"
SkinID="selecttimesheet" CommandName="Select" />
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="tableAlternatingItemStyle"
onmouseover="this.style.backgroundColor='Silver'"
onmouseout="this.style.backgroundColor='#CCFFFF'">
<td>
<asp:Label ID="lblWorkerID" runat="server"
Text='<%# Bind("Worker_ID") %>' Visible="false" />
</td>
<td>
<asp:Label ID="lblProbation" runat="server" Width="200"
Text='<%# Bind("Description") %>' />
</td>
<td align="center">
<asp:Label ID="lblDateDue" runat="server" Width="100"
Text='<%# Bind("DateDue", "{0:d}") %>' />
</td>
<td align="center">
<asp:Label ID="lblDateCompleted" runat="server" Width="100"
Text='<%# Bind("DateCompleted") %>' />
</td>
<td align="center">
<asp:Label ID="lblCompletedBy" runat="server" Width="100"
Text='<%# Bind("CompletedBy") %>' />
</td>
<td>
<asp:ImageButton ID="btnSelect" runat="server"
SkinID="selecttimesheet" CommandName="select" />
</td>
</tr>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr id="Tr2" runat="server" class="tableHoursHeaderStyle">
<th id="Th1" runat="server" style="width:0px;"></th>
<th id="Th2" runat="server">Appraisal</th>
<th id="Th3" runat="server">Date Due</th>
<th id="Th13" runat="server">Date Completed</th>
<th id="Th4" runat="server">Completed By</th>
<th id="Th6" runat="server" style="width:0px;"></th>
</tr>
<tr>
<td colspan="4">
<p>No Probations available</p>
</td>
</tr>
</table>
</EmptyDataTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table ID="itemPlaceholderContainer" runat="server"
border="0" class="TimeSheet_Table" style="">
<tr id="Tr2" runat="server"
class="tableHoursHeaderStyle">
<th id="Th1" runat="server" style="width:0px;"></th>
<th id="Th2" runat="server">Appraisal</th>
<th id="Th3" runat="server">Date Due</th>
<th id="Th13" runat="server">Date Completed</th>
<th id="Th5" runat="server">Completed By</th>
<th id="Th7" runat="server" style="width:0px;"></th>
</tr>
<tr ID="itemPlaceholder" runat="server"></tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
Edited to show markup/bindings on request
Your CompletedBy field is actually typed as a collection of a class that has a single string field. Because you are using a select new { name = ... } you are actually creating a class that looks like this which is not what you want at all:
class Anonymous9
{
public name { get; set; }
}
And, in addition, you are creating a IEnumerable<Anonymous9> which is collection of those objects.
Instead, you just want a single string. To get it to be just a single string, get rid of the new {} and wrap it with FirstOrDefault():
CompletedBy = (from ap2 in db.Appraisals
join w2 in db.Workers
on ap2.CompletedBy equals w2.Worker_ID
select w2.Surname + ", " + w2.FirstName
).FirstOrDefault()
This is my repeater control with data coming from [Patient_Master] table. But Visit_Date is coming from [Patient_Visit] table. How can I show Visit_Date to the same repeater? Is it possible to give two datasources to one repeater? [Patient_Master] and [Patient_Visit] have a relation:
<asp:Repeater ID="repeaterPatientList" runat="server" OnItemDataBound="repeaterPatientList_ItemDataBound" >
<ItemTemplate>
<tr onclick="selectRow(this);">
<td class="csstablelisttd" style="display:none" >
<asp:Label ID="lblPID" runat="server" Text='<%#Eval("PID")%>'></asp:Label>
</td>
<td class="csstablelisttd" >
<%#Eval("Patient_Name")%>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblPatientName" runat="server" Text='<%#Eval("Patient_ID")%>'></asp:Label>
</td>
<td class="csstablelisttd" >
<asp:Label ID="lblSex" runat="server" Text='<%#Eval("Sex")%>'></asp:Label>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblPatientsBirthDate" runat="server" Text='<%#Eval("Patients_Birth_Date")%>'></asp:Label>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblLastVisitDate" runat="server" Text='<%#Eval("Visit_Date")%>'></asp:Label>
</td>
<td class="csstablelisttd">
New
</td>
<td id="tdTodaysVisit" bgcolor="#00cc66" runat="server">
<span class="cssgreen">Today's Visit</span>
</td>
<td class="csstablelisttd">
<%--<asp:HyperLink ID="lnkSchedule" CssClass="csshyperlinkSchedulePatient" runat="server" NavigateUrl='<%# Eval("PID", "~/Create_Order.aspx?ID={0}") %>'>Schedule</asp:HyperLink>--%>
Schedule
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
Why don't you use an outer join between patient_master and patient_visit.
I got a table with 2 nested tables inside that display my two repeaters. My repeaters display Home and office addresses respectively. The problem is that whenever I add a new record in one repeater, the other repeater table's display gets messed up. Like if I add a record in rpt1 , then table for rpt1 moves up and table for rpt2 goes down..ie the headers do not display in one single line . They move up and down when records are added or deleted. WHat I want is these headers to be fixed so if I add new records or delete records, the headings of both repeaters display on the same line...How do I fix this ? Hope its not confusing.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">
<asp:Panel ID="pnlAddAddress" runat="server">
<asp:Repeater ID="rpt1" OnItemCommand="rpt1_ItemCommand" runat="server" OnItemDataBound="rpt1_OnItemDataBound">
<HeaderTemplate>
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressB" runat="server" Text='<%# Eval("Address1")%>' CommandName="DisplayAddressB" CommandArgument='<%#Eval("AddID") %>' CausesValidation=false></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<%-- Visible='<%# Eval("IsDefault")%>'--%>
<asp:LinkButton ID="lnkDefaultB" Text="Set as Default" CommandName="SetDefaultB" runat="server" CommandArgument='<%# Eval("AddID") + "," + Eval("IsB") %>'
CausesValidation="false" Visible='<%# Eval("IsDefault")%>'></asp:LinkButton>
<asp:Label ID="labelDefaultB" Text="Yes" runat="server" Visible='<%# Eval("IsDefault")%>'></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlSping" runat="server">
<asp:Repeater ID="rpt12" OnItemCommand="rpt12_ItemCommand" runat="server" OnItemDataBound="rptSpping_OnItemDataBound">
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressS" runat="server" Text='<%# Eval("Address1")%>' CommandArgument='<%#Eval("AddID") %>' CommandName="DisplayAddressS" CausesValidation="false"></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<asp:LinkButton ID="lnkDefaultS" Text="Set as Default" CommandName="SetDefaultS" runat="server" Visible=true CommandArgument='<%# Eval("AddID") + "," + Eval("IsS") %>'
CausesValidation="false"></asp:LinkButton>
<asp:Label ID="labelDefaultS" Text="Yes" runat="server" Visible=true></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" Text="Edit" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
</tr>
</table>
Use css attribute valign and set its value to top like this <td width="50%" valign="top">.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" valign="top">
<asp:Panel ID="pnlAddAddress" runat="server">
......
</asp:Panel>
</td>
<td valign="top">
<asp:Panel ID="pnlSping" runat="server">
......
</asp:Panel>
</td>
</tr>
</table>
For headers look to use the <th> element, this will keep them at the top of the table.
Put the <table> tags you do have outside your repeater controls, make sure the repeater only renders a single row and the same for the header.
Unless you have good reason consider just wrapping the two tables in <div> tags as nested tables really don't work ideally for layout.