jQuery DataTable not working with ListVew ASP.NET - asp.net

I'm trying to learn to use listviews instead repeaters all the time with Jquery datatables for more functionality but I'm having a hard time trying to bind it with 0 values in database
Here's my code
<asp:ListView ID="lstArtigos" runat="server" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table id="tblArtigos" class="table table-bordered dataTable">
<thead class="thead-dark">
<tr>
<th style="width: 20px;">ID</th>
<th style="width: 120px">Ref. Cliente</th>
<th style="width: 100px">Ref. Interna</th>
<th style="width: 100px">Nome</th>
<th style="width: 100px">Estado</th>
<th style="width: 100px">Logística</th>
<th style="width: 100px">Info Logística</th>
<th style="width: 100px">Data Criação</th>
<th style="width: 10px;">Editar</th>
<th style="width: 10px;">Validar</th>
<th style="width: 10px;">Rejeitar</th>
</tr>
</thead>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<asp:Label ID="lblIdArtigo" Text="<%# Eval("IdArtigo") %>"></asp:Label></td>
<td>
<asp:Label ID="lblRefCliente" Text="<%# Eval("ReferenciaCliente") %>"></asp:Label></td>
<td>
<asp:Label ID="lblRefInterna" Text="<%# Eval("ReferenciaInterna") %>"></asp:Label></td>
<td>
<asp:Label ID="lblNome" Text="<%# Eval("Nome") %>"></asp:Label></td>
<td>
<asp:Label ID="lblEstado" Text="<%# Eval("EstadoArtigo") %>"></asp:Label></td>
<td>
<asp:Label ID="lblAprovadoLogistica" Text="<%# Eval("AprovadoLogistica") %>"></asp:Label></td>
<td>
<asp:Label ID="lblInformacaoLogistica" Text="<%# Eval("InformacaoLogistica") %>"></asp:Label></td>
<td>
<asp:Label ID="lblDataCriacao" Text="<%# Eval("DataCriacao") %>"></asp:Label></td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Buttons/edit.png" CssClass="" Width="25" runat="server" />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Buttons/success.png" CssClass="" Width="25" runat="server" />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Buttons/x-button.png" CssClass="" Width="25" runat="server" />
</td>
</ItemTemplate>
</asp:ListView>
and in codebehind I bind it with datatable even if it comes empty from database it should appear the jquery message like it does on repeater
private void BindArtigos(int id)
{
lstArtigos.DataSource = Requisicao.GetAll(id);
lstArtigos.DataBind();
}
Also there is no problem with Jquery plugin cause I had a repeater before writing the listview and was working properly
EDIT:
Added the missing columns on table header, still shows nothing and no errors on console

The problem is that you have more cells in the body of the table that in the thead. They must be the same.
<thead class="thead-dark">
<tr>
<th style="width: 20px;">ID</th>
<th style="width: 120px">Ref. Cliente</th>
<th style="width: 100px">Ref. Interna</th>
<th style="width: 100px">Nome</th>
<th style="width: 100px">Logística</th>
<th style="width: 100px">Estado</th>
<th style="width: 10px;">Editar</th>
<th style="width: 10px;">Validar</th>
<th style="width: 10px;">Rejeitar</th>
//add these
<th># 1</th>
<th># 2</th>
</tr>
</thead>

<td>
<asp:Label ID="lblIdArtigo" Text="<%# Eval("IdArtigo") %>"></asp:Label></td>
replace this line with
<td>
<asp:Label ID="lblIdArtigo" Text='<%# Eval("IdArtigo") %>'></asp:Label></td>
and check if it shows data
check out this article
https://www.c-sharpcorner.com/UploadFile/9de7db/listview-control-in-Asp-Net/

Related

ItemTemplate misplaced inside a table

So, I tried to fill in a ItemRepeater inside a table. But I think there is some kind of error, in the indentation. Code is like this:
<div class="card-body border-bottom bg-white">
<asp:UpdatePanel ID="upFromHome" runat="server">
<ContentTemplate>
<asp:ListView ID="lsHome" runat="server">
<LayoutTemplate>
<div class="col">
<table runat="server" id="tableHome" class="table-bordered table-striped mb-0 table table-responsive">
<thead>
<tr style="text-align: center; font-size: 12px;">
<th scope="col">Employee Id</th>
<th scope="col">Type</th>
<th scope="col">Day</th>
<th scope="col">Month</th>
<th scope="col">Year</th>
<th scope="col">Status</th>
</tr>
</thead>
<tr runat="server" id="itemPlaceholder">
</table>
</LayoutTemplate>
<ItemTemplate> //error is here
<tbody>
<tr runat="server" style="text-align: center; background-color: white; font-size: 11px;">
<th runat="server" style="text-align: center;">
<asp:Label ID="lblUsername" runat="server" Text='<%#Eval("username") %>'></asp:Label></th>
<th runat="server" style="text-align: center;">
<asp:Label ID="lblTipo" runat="server" Text='<%#Eval("tipo") %>' /></th>
<td runat="server" style="text-align: left;">
<asp:Label ID="lblDay" runat="server" Text='<%#Eval("fecha") %>' /></td>
<td runat="server" style="text-align: left;">
<asp:Label ID="lblMes" runat="server" Text='<%#Eval("regHorario") %>' /></td>
<td runat="server" style="text-align: left;">
<asp:Label ID="lblAno" runat="server" Text='<%#Eval("status") %>' /></td>
<td runat="server" style="text-align: center;">
<asp:Button runat="server" ID="status1" class="btn btn-success" Text="Approved" /></td>
</tr>
</tbody>
</ItemTemplate>
</asp:ListView>
</div>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
But even tho, the code behind in asp works well... I am getting an error in the frontend. This is the error:
System.Web.UI.HtmlControls.HtmlTableCellCollection debe tener elementos de tipo 'System.Web.UI.HtmlControls.HtmlTableCell'. 'ItemTemplate' es de tipo 'System.Web.UI.HtmlControls.HtmlGenericControl'.
Apparently it is misplaced in some div node, but this is the first time I am getting this error.
You started an ItemTemplate without first declaring the table. So:
<ItemTemplate> //error is here
<tbody>
<tr runat="server" style="text-align: center; background-color: white; font-size: 11px;">
the correct thing is to declare the table first:
<ItemTemplate> //error is here
<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr runat="server" style="text-align: center; background-color: white; font-size: 11px;">
</tr>
...
</tbody>
</table>

asp.net TextBox not updating in IE11

I have migrated my .net projet from framework 3.5 to 4.5 and my the site was previously running under IE7.
I need to run it under IE11 now. I have a page which upon selecting an element in a dropdown display the values of the element selected.
The element has 3 different fields:
Code, name and info et a button delete which upon clicking delete the element and empty the fields.
Below is the code which does the reset:
protected void LB_Supprimer_Click(object sender, System.EventArgs e)
{
if ( this.DBDelete_TRF() )
{
this.TB_NOM.Text = "" ;
this.TB_CODE.Text = "" ;
this.TB_ACTCORR.Text = "" ;
}
MngMessage.refresh();
}
Code in aspx:
<TABLE id="Table1" borderColor="lightgrey" cellSpacing="5" cellPadding="0" width="100%"
border="0">
<TR>
<TD style="WIDTH: 168px; HEIGHT: 19px" align="right">
<asp:Label id="Lbl_code" runat="server" CssClass="label" DESIGNTIMEDRAGDROP="47">Code : </asp:Label></TD>
<TD style="WIDTH: 403px; HEIGHT: 19px">
<asp:TextBox id="TB_CODE" runat="server" Width="96px" CssClass="txt" DESIGNTIMEDRAGDROP="73"
ToolTip="Code" Font-Bold="True" ontextchanged="TB_CODE_TextChanged"></asp:TextBox>
</TD>
</TR>
<TR>
<TD style="WIDTH: 168px; HEIGHT: 68px" align="right">
<asp:Label id="Label_Nom" runat="server" CssClass="label" DESIGNTIMEDRAGDROP="86">Nom : </asp:Label></TD>
<TD style="WIDTH: 403px; HEIGHT: 68px">
<asp:TextBox id="TB_NOM" runat="server" Height="54px" Width="360px" CssClass="txt" DESIGNTIMEDRAGDROP="85"
Font-Bold="True" TextMode="MultiLine" Rows="4"></asp:TextBox></TD>
</TR>
<TR>
<TD style="WIDTH: 168px" align="right"></TD>
<TD style="WIDTH: 403px">
<asp:Label id="LB_INFO" runat="server" CssClass="label">Info</asp:Label></TD>
</TR>
<TR>
<TD style="WIDTH: 168px" align="right">
<asp:Label id="Label8" runat="server" CssClass="label" DESIGNTIMEDRAGDROP="49">Action : </asp:Label>
<asp:CheckBox id="chk_Confirmee" runat="server" CssClass="DBLabel" ToolTip="xxx yyy"
Text="Confirmée"></asp:CheckBox></TD>
<TD style="WIDTH: 403px">
<asp:TextBox id="TB_ACTCORR" runat="server" Height="74px" Width="360px" CssClass="txt" TextMode="MultiLine"
Rows="5"></asp:TextBox></TD>
</TR>
<TR>
<TD align="center" height="15"><cc1:linkbutton id="LB_Supprimer" runat="server" DisableText="Traitement en cours" DisableAfterClick="True" onclick="LB_Supprimer_Click">Supprimer</cc1:linkbutton></TD>
</TR>
</TABLE>
The above does not work in IE11 only but in chrome it does.
Any idea how to solve this pls?

Access "th" in Listview

Is there a way to access the "th", in the code behind. I would like to add padding to the header depending on the item value.
<LayoutTemplate>
<table runat="server" >
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" class="UserLayoutTbl">
<tr runat="server" style="">
<th runat="server" width="140" align="left">
Date</th>
<th runat="server" width="140" align="left">
Ref. No.</th>
<th runat="server" width="270" align="left">
Description</th>
<%-- <th runat="server" width="90" align="right" style = '<%# GetAmountLabelStyle() %>'>
Amount</th>--%>
<th id="Th1" runat="server" width="90" align="right">
Amount</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
First, give an ID to the element you want to change. After DataBind of the ListView, you can access the control by its ID using the FindControl method of the ListView. Then, you can convert the returned control to HtmlTableCell to proper handle it:
// thDate is the <th> ID
HtmlTableCell thDate = lstItems.FindControl("thDate") as HtmlTableCell;

Modal popup extender not displaying popup

I have inherited some code using an ASP modal popup extender and for some reason it has now decided to stop working. Am I missing anything here? I'm not too fluent with AJAX / ASP.Net right now so im struggling to diagnose what is going wrong here.
So firstly the javascript method that displays the modal
function ShowModalRemoveEvent(ID, EventID, InstructorID, InstructorName)
{
alert("Hi");
var modal = $find('ModalPopupExtender1');
modal.show();
document.getElementById("txtID").value = ID;
document.getElementById("txtEventID").value = EventID;
document.getElementById("txtInstructorID").value = InstructorID;
document.getElementById("txtInstructorName").value = InstructorName;
}
I know this is being called because of the alert. So I would assume the prpblem is either in finding the ModalPopupExtender1 or the modal.show() line.
Here is the code for my modal popup extender
<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="Panel4" runat="server" Style="display: none" CssClass="ModalBackground">
<table style="width: 100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="7%" class="cellAlertHeader">
<img src="../../../images/Ops/window_delete.png" style="width: 18px; height: 18px" alt=""/>
</td>
<td width="93%" class="cellAlertHeader">
<b>Cancel Instructor Event</b>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="5%">
<td width="95%">
<asp:TextBox ID="txtID" Style="display: none" runat="server" CssClass="TextboxTitle"></asp:TextBox>
<asp:TextBox ID="txtEventID" Style="display: none" runat="server" CssClass="TextboxTitle"></asp:TextBox>
</td>
</tr>
<tr>
<td width="5%">
</td>
<td width="95%">
<asp:TextBox ID="txtInstructorID" Style="display: none" runat="server" BorderStyle="None"
CssClass="TextboxTitle"></asp:TextBox>
<asp:TextBox ID="txtInstructorName" Style="font-size: 12px" runat="server" BorderStyle="None"
CssClass="TextboxTitle" BorderWidth="0"></asp:TextBox>
</td>
</tr>
<tr>
<td width="5%">
</td>
<td width="95%">
</td>
</tr>
<tr>
<td width="5%">
</td>
<td width="95%">
<asp:Label ID="Label2" runat="server" Text="Are you sure you want to remove this Event?"
CssClass="TextboxTitle"></asp:Label>
</td>
</tr>
<tr>
<td width="5%">
</td>
<td width="95%">
</td>
</tr>
<tr>
<td width="5%">
</td>
<td width="95%">
<asp:Button ID="ButtonConfirmRemove" runat="server" Text="Confirm" CssClass="buttonshort" />
<asp:Button ID="ButtonCancel" runat="server" Text="Cancel" CssClass="buttonshort" />
</td>
</tr>
<tr>
<td width="5%">
</td>
<td width="95%">
</td>
</tr>
</table>
</asp:Panel>
<asp:Button runat="server" ID="dummyButton" Style="display: none" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1"
runat="server"
PopupControlID="Panel4"
TargetControlID="dummyButton"
BackgroundCssClass="ModalBGOpacity"
CancelControlID="ButtonCancel"
OnCancelScript="HideModalPopup()">
</cc1:ModalPopupExtender>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="dummyButton" />
</Triggers>
</asp:UpdatePanel>
Try getting the rendered id of your control, like that.
var modal = $find('<%=ModalPopupExtender1.CliendID%>');

Toggle rows created using Repeater Control ASP.NET

I am creating a list of data using Repeater Control. Some of the rows might have other rows that should be toggled using the main row's clickable image.
Here, is the HTML part
<table cellpadding="2" cellspacing="0" width="100%">
<asp:Repeater ID="repeatLockers" runat="Server">
<HeaderTemplate>
<tr>
<td> </td>
<td>A</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr id="trItem" class="SomeParentClass" runat="server">
<td>
<img id="imgToggleHomeInfo" runat="server" alt="show/hide repetitves" src="icon_plus.gif"
style="cursor: pointer" />
</td>
<td>
<asp:Label ID="lbl" runat="server"></asp:Label>
</td>
</tr>
<tr id="trAddOnFee" runat="server" class="SomeClass" style="display: none;">
<td colspan="2">
<table cellpadding="4" cellspacing="2" width="100%">
<tr>
<td class="DgHeader">A</td>
<td class="DgHeader">B</td>
</tr>
<asp:Repeater ID="repeatRepetitives" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblA" runat="server"></asp:Label>
</td>
<td align="right">
<asp:Label ID="lblB" runat="server"></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
How could I toggle the Rows with class as "SomeClass" inside on click of imgToggleHomeInfo" image on its parent row using Jquery?
I'd find the parent row of the image then toggle it's next sibling.
$(document).ready( function() {
$("[id$='imageToggleHomeInfo']").click( function() {
$(this).closest('tr').next().toggle();
});
})

Resources