Is there a way to put the following code in a gridview so I can do paging without updating the entire page.
<ASP:PANEL id="ResultsPanel" border="1" HorizontalAlign="Center" runat="server" Width="100%">
<ASP:REPEATER id="SearchResultsRepeater" runat="server" EnableViewState="False">
<HEADERTEMPLATE>
<TABLE BORDER="1" Style="width:800px"" Align="center" >
<TR>
<TD Class="StdSectionHeader2" Style="color: #FFFFFF;" Colspan="8">Select a Provider Name</TD>
</TR>
<TR>
<TH ID="header1" Class="StdTablePadding5 BlueTD" >Name</TH>
<TH ID="header2" Class="StdTablePadding5 BlueTD">Service Area</TH>
<TH ID="header4" Class="StdTablePadding5 BlueTD">Gender</TH>
<TH ID="header5" Class="StdTablePadding5 BlueTD">City</TH>
<TH ID="header6" Class="StdTablePadding5 BlueTD">Zip Code</TH>
<TH ID="header7" Class="StdTablePadding5 BlueTD">Processing<BR />Status</TH>
<TH ID="header8" Class="StdTablePadding5 BlueTD">Phone</TH>
</TR>
</HEADERTEMPLATE>
<ITEMTEMPLATE>
<TD Class="StdTablePadding5"><a class="three" href="default.asp" target="_blank">
<%# getStartLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString() )%>
<%# getNextPage(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString(),HCQA.ReferralRegistry.UI.Validation.EncodeDigits(((HCQA.ReferralRegistry.UI.User)Session["User"]).EncryptionKey,DataBinder.Eval(Container.DataItem, "IndividualID").ToString()))%>
<%# getMidLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString())%>
<%# DataBinder.Eval(Container.DataItem, "IndividualName").ToString()%>
<%# getEndLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString())%></a>
</TD>
<TD HEADERS="header2" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ServiceAreaName") %></TD>
<TD HEADERS="header4" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "gender") %></TD>
<TD HEADERS="header5" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "city") %></TD>
<TD HEADERS="header6" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ZipCode") %></TD>
<TD HEADERS="header7" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ProcessingStatus") %></TD>
<TD HEADERS="header8" Class="StdTablePadding5"><%# Util.FormatPhoneNumber(DataBinder.Eval(Container.DataItem, "PhoneNumber").ToString().Trim())%></TD>
</TR>
</ITEMTEMPLATE>
<ALTERNATINGITEMTEMPLATE>
<TR CLASS="AlternatingItemTemplate">
<TD HEADERS="header1" Class="StdTablePadding5">
<%# getStartLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString() )%>
<%# getNextPage(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString(),HCQA.ReferralRegistry.UI.Validation.EncodeDigits(((HCQA.ReferralRegistry.UI.User)Session["User"]).EncryptionKey,DataBinder.Eval(Container.DataItem, "IndividualID").ToString()))%>
<%# getMidLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString())%>
<%# DataBinder.Eval(Container.DataItem, "IndividualName").ToString()%>
<%# getEndLink(DataBinder.Eval(Container.DataItem, "ServiceAreaName").ToString())%>
</TD>
<TD HEADERS="header2" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ServiceAreaName") %></TD>
<TD HEADERS="header4" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "gender") %></TD>
<TD HEADERS="header5" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "city") %></TD>
<TD HEADERS="header6" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ZipCode") %></TD>
<TD HEADERS="header7" Class="StdTablePadding5"><%# DataBinder.Eval(Container.DataItem, "ProcessingStatus") %></TD>
<TD HEADERS="header8" Class="StdTablePadding5"><%# Util.FormatPhoneNumber(DataBinder.Eval(Container.DataItem, "PhoneNumber").ToString().Trim())%></TD>
</TR>
</ALTERNATINGITEMTEMPLATE>
<FOOTERTEMPLATE>
</table>
</FOOTERTEMPLATE>
</ASP:REPEATER>
Related
I have two tables. First works fine - if button ID="Button1" CommandName="Select" pressed selected item turns red. But second table doesn't do the same if I pressed it's own button ID="Button2" CommandName="Select".
first table listView ID="ListViewGrSDtudents"
second table listView ID="ListViewGroups"
Does somebody now what why it doesn't work?
It's my .aspx code:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<!-- Таблица групп -->
<div>
<asp:ListView ID="ListViewGroups"
runat="server"
ItemType="BD_Class_Library.studentGroup"
DataKeyNames="groupId"
SelectMethod="GetStudGroups"
InsertMethod="InsertStudGroup"
UpdateMethod="UpdateGroup"
DeleteMethod="DeleteGroup"
OnSelectedIndexChanged="ListViewGroups_SelectedIndexChanged">
<InsertItemTemplate>
<tr style="background-color: yellowgreen">
<td></td>
<td>
<input id="groupName" runat="server" value="<%# BindItem.groupName %>" /></td>
<td>
<asp:Button ID="Button1" Width="100%" CommandName="Insert" runat="server" Text="Вставить" />
</td>
</tr>
</InsertItemTemplate>
<EditItemTemplate>
<tr style="background-color: yellow">
<td><%# Item.groupId %></td>
<td>
<input id="groupName" runat="server" value="<%# BindItem.groupName %>" /></td>
<td>
<asp:Button CommandName="Update" runat="server" Text="Сохранить" />
<asp:Button CommandName="Cancel" runat="server" Text="Отмена" />
</td>
</tr>
</EditItemTemplate>
<LayoutTemplate>
<table border="1">
<tr style="background-color: darkgray">
<th>ID</th>
<th>Группа</th>
<th></th>
</tr>
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color: red">
<td><%# Item.groupId %></td>
<td><%# Item.groupName %></td>
<td>
<asp:Button CommandName="Edit" runat="server" Text="Изменить" />
<asp:Button CommandName="Delete" runat="server" Text="Удалить" />
</td>
</tr>
</SelectedItemTemplate>
<ItemTemplate>
<tr style="background-color: grey">
<td><%# Item.groupId %></td>
<td><%# Item.groupName %></td>
<td>
<asp:Button CommandName="Select" runat="server" Text="Выбрать" />
<asp:Button CommandName="Edit" runat="server" Text="Изменить" />
<asp:Button CommandName="Delete" runat="server" Text="Удалить" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</div>
<div>
<asp:ListView
ID="ListViewGrSDtudents"
runat="server"
ItemType="BD_Class_Library.student"
DataKeyNames="studId"
OnSelectedIndexChanging="ListViewGrSDtudents_SelectedIndexChanging"
OnSelectedIndexChanged="ListViewGrSDtudents_SelectedIndexChanged">
<SelectedItemTemplate>
<tr style="background-color: red">
<td><%# Item.studId %></td>
<td><%# Item.studFam %></td>
<td><%# Item.studName %></td>
<td><%# Item.studOtc %></td>
<td><%# Item.studBiletNum %></td>
</tr>
</SelectedItemTemplate>
<ItemTemplate>
<tr style="background-color: grey">
<td><%# Item.studId %></td>
<td><%# Item.studFam %></td>
<td><%# Item.studName %></td>
<td><%# Item.studOtc %></td>
<td><%# Item.studBiletNum %></td>
<td><asp:Button ID="Button2" CommandName="Select" runat="server" Text="Выбрать" /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table border="1" style="width: 60%">
<tr id="groupPlaceholder" runat="server"></tr>
<tr style="background-color: aqua">
<th>ID студента</th>
<th>Фамилия</th>
<th>Имя</th>
<th>Отчество</th>
<th>Студ. билет</th>
</tr>
<tr id="itemPlaceholder" runat="server" itemplaceholderid="itemPlaceholderStudent"></tr>
</table>
</LayoutTemplate>
<EmptyDataTemplate>
<table border="1" style="width: 60%">
<tr style="background-color: aqua">
<th>ID студента</th>
<th>Фамилия</th>
<th>Имя</th>
<th>Отчество</th>
<th>Студ. билет</th>
<th></th>
</tr>
<tr style="background-color: grey">
<td colspan="5" style="text-align: center">В данной группе нет студентов</<td>
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
event - ListViewGrSDtudents_SelectedIndexChanged code:
protected void ListViewGrSDtudents_SelectedIndexChanged(object sender, EventArgs e)
{
int selStudent = (int)ListViewGrSDtudents.SelectedDataKey.Value;
Session["SelectedStudent"] = selStudent;
Session["SelectedStudentIndex"] = ListViewGrSDtudents.SelectedIndex;
Response.Redirect("~/Default.aspx");
}
Description Part 1
Description Part 2
I fetch data by using a selectmethod and it works fine , the problem is that I don't want a new table for each record inserted. I'd like a new column to be added to the existing table. Something like the picture below
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView ID="FormView1" runat="server" ShowHeader="False" ItemType="MieleRepresentative.SteamBoiler" SelectMethod="GetSteamBoilerModels" RenderOuterTable="false" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table class="table-striped table-bordered">
<tr style="background-color: thistle!important;">
<td style="font-weight: bold;">Model</td>
<td><%# Eval("Model")%></td>
</tr>
<tr>
<td style="font-weight: bold">WorkingPressureLimit</td>
<td><%# Eval("WorkingPressureLimit")%></td>
</tr>
<tr>
<td style="font-weight: bold">TestPressureLimit</td>
<td><%# Eval("TestPressureLimit")%></td>
</tr>
<tr>
<td style="font-weight: bold">Electrical</td>
<td><%# Eval("Electrical")%></td>
</tr>
<tr>
<td style="font-weight: bold">Diameter</td>
<td><%# Eval("Diameter")%></td>
</tr>
<tr>
<td style="font-weight: bold">Height</td>
<td><%# Eval("Height")%></td>
</tr>
<tr>
<td style="font-weight: bold">Weight</td>
<td><%# Eval("Weight")%></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
public IQueryable<SteamBoiler> GetSteamBoilerModels([QueryString("productID")] Guid productId)
{
var _mieleDbEntities = new MieleDBEntities();
return _mieleDbEntities.SteamBoilers.Where(boiler => boiler.FKProduct == productId);
}
If you want a table with an undefined number of columns (one for each record selected), probabily GridView is not your best bet.
In my opinion you should build dynamically your table in .aspx page in this way:
<% var steamBoilersList = GetSteamBoilerModels(...params...); %>
<table>
<!-- first row -->
<tr>
<% foreach (var singleSteamBoiler in steamBoilersList) { %>
<td>
<%= singleSteamBoiler.FIELD1 %>
</td>
</tr>
<!-- second row and so on -->
<tr>
<% foreach (var singleSteamBoiler in steamBoilersList) { %>
<td>
<%= singleSteamBoiler.FIELD2 %>
</td>
</tr>
</table>
I'm currently trying to paginate a list of records, however; after the last table, the page break leaves an empty page. The set up is an Aspx files that incorporates two ascx files to draw the table records.
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Table.ascx.cs" Inherits="%>
<br class="clear" /><br/>
<table class="report-table" cellspacing="0" cellpadding="2">
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("PatientBills") %>' OnItemDataBound="Repeater1_OnItemDataBound">
<HeaderTemplate>
<tr>
<td>Seq</td>
<td>Billing Id</td>
<td>Patient Id</td>
<td>Patient Name</td>
<td>Sex</td>
<td class="PrintNormalWrap">Admit Date</td>
<td class="PrintNormalWrap" style="width: 80px;">Social Security</td>
<td>DOB</td>
<td>POS</td>
<td>CPT</td>
<td>Mods</td>
<td style="width: 220px;">Diagnosis</td>
<td class="PrintNormalWrap">Referring Provider(UPIN)/ Comment</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="billRowShade<%# Container.ItemIndex % 2 %>">
<asp:TableCell ID="tableCellSequence" runat="server"><%# Container.ItemIndex + 1 %></asp:TableCell>
<td><%# FormatBillingId(Eval("Bill.BillingId")) %></td>
<td><%# FormatField(Eval("Patient.PatientId")) %></td>
<td id="printPatientName"><%# FormatField(Eval("Patient.LastName")) %>, <%# FormatField(Eval("Patient.FirstName")) %></td>
<td><%# FormatField(Eval("Patient.Sex")) %></td>
<td><%# FormatShortDate(Eval("Patient.DateOfAdmittance"))%></td>
<td><%# FormatField(Eval("Patient.SocialSecurityNumber")) %></td>
<td><%# FormatShortDate(Eval("Patient.DateOfBirth"))%></td>
<td><%# FormatField(Eval("Bill.Pos")) %></td>
<td><%# FormatField(Eval("Bill.CptCode")) %></td>
<td><%# FormatField(Eval("Bill.Mod")) %></td>
<td><%# FormatDiagnoses(Eval("Bill.Diagnoses"), Eval("Bill.BillDate"), Eval("Bill.SiteName")) %></td>
<td class="PrintNormalWrap"><%# FormatNotes(Eval("Patient.ReferringMd"), Eval("Patient.RefUpin"), Eval("Bill.Notes"), Eval("Bill.TimeEntry")) %> <%# FormatSupervisor( Eval("Bill.SupervisedByName"), Eval("Bill.DoctorName") ) %></td>
</tr>
<asp:TableRow ID="tableRowSpecialtyFieldDetails" runat="server" CssClass="specialtyFieldDetails">
<asp:TableCell ID="TableCell1" colspan="12" runat="server"><span id="spanSpecialtyFieldDetails" runat="server"></span></asp:TableCell>
</asp:TableRow>
</ItemTemplate>
</asp:Repeater>
</table>
<p style="page-break-after:always"></p>
<br/>
i tried and get the sum of two numbers by getting through eval
<%# Convert.ToDecimal(Eval("total"))+ Convert.ToDecimal(Eval("tax")) %>
by doing this i got the sum of (total + tax)
now i need to find the division. Is it possible to divide like <%# Convert.ToDecimal(Eval("total"))/ Convert.ToDecimal(Eval("qty")) %> the above.
my code in detail
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td class="text-left"><%#Eval("rowId") %></td>
<td><%#Eval("product_name") %> - <%#Eval("product_des") %></td>
<td class="text-center"><%#Eval("qty") %></td>
<td class="text-center"><%#Eval("uom") %></td>
<td class="text-center"><%#Eval("tax_percent") %></td>
<td class="text-right"><%# Convert.ToDouble(Convert.ToDecimal(Eval("total"))/ Convert.ToDecimal(Eval("qty")))%></td>
<td class="text-right"><%# Convert.ToDecimal(Eval("total"))+ Convert.ToDecimal(Eval("tax")) %></td>
<td class="text-center"><%#Eval("type") %></td>
<td class="text-right">
<asp:ImageButton ID="ibtnEdit" runat="server" ImageUrl="assets/btn/edit_btn.png" OnClick="ibtnEdit_Click" CommandArgument='<%#Eval("rowId") %>' />
<asp:ImageButton ID="ibtn_Delete" runat="server" ImageUrl="assets/btn/delete_btn.png" OnClick="ibtn_Delete_Click" CommandArgument='<%#Eval("rowId") %>' OnClientClick="return confirm('Are you sure you want to delete?');" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
please help me. thanks in advance
I'm trying to sum all the values from the July column into a label with ID of july. Here's the markup:
<asp:ListView ID="leaveListView" runat="server" ItemPlaceholderID="itemPlaceholder" OnItemDataBound="leaveListView_ItemDataBound">
<LayoutTemplate>
<table class="budgetList">
<thead>
<tr>
<td>Project Number</td>
<td>Account</td>
<td>Project Name</td>
<td>July</td>
</tr>
</thead>
<tbody>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</tbody>
<tfoot>
<tr class="projectRowTotal">
<td>Project Totals</td>
<td></td>
<td></td>
<td><asp:Label ID="july" runat="server" Text=""></asp:Label></td>
</tr>
</tfoot>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="<%# Container.DataItemIndex % 2 == 0 ? "" : "even" %>">
<td><%# Eval("Project") %></td>
<td><%# Eval("Account") %></td>
<td><%# Eval("ProjectNumber") %></td>
<td><%# Eval("July") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
I'm using the ItemDataBound event to sum, but it's returning null. This is the code-behind:
decimal july = 0m;
protected void leaveListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
july += Convert.ToDecimal(e.Item.FindControl("July"));
}
Label julySum = (Label)leaveListView.FindControl("july");
julySum.Text = string.Format("{0:C}", (decimal?)july);
}
What do I need to do to get this to work?
as my comments suggested, here is solution:
<table class="budgetList">
<thead>
<tr>
<td>Project Number</td>
<td>Account</td>
<td>Project Name</td>
<td>July</td>
</tr>
</thead>
<tbody>
<asp:ListView ID="leaveListView" runat="server" ItemPlaceholderID="itemPlaceholder">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<tr class="<%# Container.DataItemIndex % 2 == 0 ? "" : "even" %>">
<td><%# Eval("Project") %></td>
<td><%# Eval("Account") %></td>
<td><%# Eval("ProjectNumber") %></td>
<td><%# Eval("July") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
</tbody>
<tfoot>
<tr class="projectRowTotal">
<td>Project Totals</td>
<td></td>
<td></td>
<td><asp:Label ID="july" runat="server" Text=""></asp:Label></td>
</tr>
</tfoot>
</table>
havent't actually tried it, but should work fine ... + in code, where you bind data:
leaveListView.ItemsSource = <data>;
// simply place the value in label directly
july.Text = <data.sum>
now just make sum in code and you're done, no need for itemdatabound event
e.Item.FindControl("July") return null because no control with that existing in the ListView
Solution
You want to store July's value into HiddenField (or some other field) so that you can retrieve them back in ItemDataBound event.
<asp:ListView ID="leaveListView"...>
<ItemTemplate>
<tr class="<%# Container.DataItemIndex % 2 == 0 ? "" : "even" %>">
<td><%# Eval("Project") %></td>
<td><%# Eval("Account") %></td>
<td><%# Eval("ProjectNumber") %></td>
<td><%# Eval("July") %></td>
</tr>
<asp:HiddenField runat="server" ID="JulyHiddenField"
Value="<%# Eval("July") %>"/>
</ItemTemplate>
</asp:ListView>
decimal july = 0m;
protected void leaveListView_ItemDataBound(object sender,
ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
var hiddenField = e.Item.FindControl("JulyHiddenField") as HiddenField;
july += Convert.ToDecimal(hiddenField.Value);
}
Label julySum = (Label)leaveListView.FindControl("july");
julySum.Text = string.Format("{0:C}", (decimal?)july);
}
For Good Design Practice
Please name your control properly. Eg. <asp:Label ID="JulyLabel" runat="server" Text=""></asp:Label>. Currently, you have no way of knowing is july is what.