Datatables not working when having nested asp:ListView? - asp.net

I'm using DataTables to get some sorting and locked header bar functionality. Problem is, when I have my nested listView the in don't match because the nested listView is filled dynamically by button click on a row. Is there any way of solving this? Datatables don't allow colspan which i think would solve it.
Datatable javascript:
$("#tbl_MainProj").DataTable({
fixedHeader: true
, bLengthChange: false
, bPaginate: false
, searching: false
, targets: 'no-sort'
, bSort: true
});
aspx.:
<asp:ListView ID="ListV_Proj" runat="server" DataSourceID="Project_ObjectDataSource" OnItemCommand="ListV_Proj_ItemCommand">
<LayoutTemplate>
<table id="tbl_MainProj" class="gvv">
<thead>
<tr>
<th>
<asp:Label Text="Sub" runat="server" />
</th>
<th>
<asp:Label Text="Nummer" runat="server" />
</th>
<th>
<asp:Label Text="Konto" runat="server" />
</th>
<th>
<asp:Label Text="Navn" runat="server" />
</th>
<th>
<asp:Label Text="Søgenavn" runat="server" />
</th>
<th>
<asp:Label Text="Rekv.nr." runat="server" />
</th>
<th>
<asp:Label Text="PL" runat="server" />
</th>
<th>
<asp:Label Text="Leveres dato" runat="server" />
</th>
<th>
<asp:Label Text="Bekr. Dato" runat="server" />
</th>
<th>
<asp:Label Text="Status" runat="server" />
</th>
</tr>
</thead>
<tr id="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:Button ID="btn_GetSubProj" Text="+" runat="server" CommandArgument='<%# Eval("Proj") %>' />
</td>
<td>
<asp:Label ID="lbl_projNo" Text='<%# Eval("Proj") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("ACCOUNT") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("NAME") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("SNAME") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("REFNO") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("EMPLOYEE") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("END_") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("CONFIRMEDDATE") %>' runat="server" />
</td>
<td>
<div id="rgy" class='<%# CalcDateExceed(Eval("END_", "{0:d}")) %>'></div>
</td>
</tr>
<tr>
<td>
<asp:ListView ID="ListView_subProj1" runat="server">
<LayoutTemplate>
<table id="tbl_subProj1">
<thead>
<tr>
<th>
<asp:Label Text="Nummer" runat="server" />
</th>
<th>
<asp:Label Text="Konto" runat="server" />
</th>
<th>
<asp:Label Text="Navn" runat="server" />
</th>
<th>
<asp:Label Text="Søgenavn" runat="server" />
</th>
<th>
<asp:Label Text="Rekv.nr." runat="server" />
</th>
<th>
<asp:Label Text="PL" runat="server" />
</th>
<th>
<asp:Label Text="Leveres dato" runat="server" />
</th>
<th>
<asp:Label Text="Bekr. Dato" runat="server" />
</th>
<th>
<asp:Label Text="Status" runat="server" />
</th>
</tr>
</thead>
<tr id="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:Label ID="lbl_projNo" Text='<%# Eval("Proj") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("ACCOUNT") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("NAME") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("SNAME") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("REFNO") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("EMPLOYEE") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("END_") %>' runat="server" />
</td>
<td>
<asp:Label Text='<%# Eval("CONFIRMEDDATE") %>' runat="server" />
</td>
<td>
<div id="rgy" class='<%# CalcDateExceed(Eval("END_", "{0:d}")) %>'></div>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I only need the Datatable functionality on the parent listView(Table). But the row containing the child listView is throwing the jQuery exception:
Unable to set property '_DT_CellIndex' of undefined or null reference.
Is there any way to solve this and keep the functionality of datatables?
Edit: looking at the Q :DataTables - Not working when added colspan for the last column
I have to use below script somehow. But i cant seem to figure it out?
"aoColumnDefs": [{
"aTargets": [2,3,4,5],
"defaultContent": ""
}]

Related

Showing same table to different roles with different options

Currently I just post the same code in different pages for each role, a repeater with a table like this one but each role has different options to do. I tried to place in loginview separator but didn't work, i don't know how to iterate through login view controls and the code just started getting dirtier more than just doing visible = false / true. Is there a more effective way to do this than just making new pages?
<asp:Repeater ID="rptArtigos" runat="server" OnItemCommand="rptArtigos_OnItemCommand" OnItemDataBound="rptArtigos_OnItemDataBound">
<HeaderTemplate>
<table id="tblArtigos" class="table table-bordered dataTable text-center">
<thead class="thead-dark">
<tr>
<th>ID</th>
<th>Ref. Cliente</th>
<th>Ref. Interna</th>
<th>Nome</th>
<th>Estado</th>
<th>Válido Logística</th>
<th>Data Criação</th>
<th></th>
<th></th>
<th id="cell1" runat="server"></th>
<th></th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody>
<tr>
<td>
<asp:Label ID="lblIdArtigo" runat="server" Text='<%# Eval("IdArtigo") %>' />
</td>
<td>
<asp:Label ID="lblRefCliente" runat="server" Text='<%# Eval("ReferenciaCliente") %>' />
</td>
<td>
<asp:Label ID="lblRefInterna" runat="server" Text='<%# Eval("ReferenciaInterna") %>' />
</td>
<td>
<asp:LinkButton ID="lkbtnNome" runat="server" Text='<%# Eval("Nome") %>' CommandName="Ver" CommandArgument='<%# Eval("IdArtigo") %>'></asp:LinkButton>
</td>
<td>
<asp:Label ID="lblEstado" runat="server" Text='<%# Eval("EstadoArtigo") %>' />
</td>
<td>
<asp:Label ID="lblAprovadoLogistica" runat="server" Text='<%# Eval("AprovadoLogistica") %>' />
</td>
<td>
<asp:Label ID="lblDataCriacao" runat="server" Text='<%# Eval("DataCriacao") %>' />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Icones/copy.png" Width="25" runat="server" CommandName="Copiar" CommandArgument='<%# Eval("IdArtigo") %>' />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Buttons/edit.png" Width="25" runat="server" CommandName="Editar" CommandArgument='<%# Eval("IdArtigo") %>' />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Buttons/success.png" Width="25" runat="server" OnClientClick="return false;" data-toggle="modal" data-target="#validate" CommandName="Validar" CommandArgument='<%# Eval("IdArtigo") %>' />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Buttons/x-button.png" Width="25" runat="server" CommandName="Rejeitar" CommandArgument='<%# Eval("IdArtigo") %>' />
</td>
</tr>
</tbody>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

For Loop or Dim for getting a handle on data from a Datagrid in a Checkbox

I am currently trying to ' Loop ' through my DataGrid to check if the boxes that are ticked to be shown on another page that pretty much looks like my existing one.
I'm having trouble finding out how to actually do a ' loop ' as they are called I think as I am a slow learner in coding , am just looking for some guidance in how I would achieve this goal of actually getting a handle on the Data. Below is my code for the ASP.GridView & well there is no VB.NET code-behind as of such because well , am stuck & need pushing the right direction .
EDIT: Forgot to mention , why cant I do this from a Dim This As String?
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" Width="100%">
<HeaderTemplate>
<table width="100%" style="font-family: Verdana; font-size: 8pt" cellpadding="0"
cellspacing="0" border="1">
<tr align="left">
<th colspan="4">
Customer:
<asp:Label ID="Customer_lab" runat="server"></asp:Label>
</th>
<th colspan="4">
Quote:
<asp:Label ID="Quote_lab" runat="server"></asp:Label>
</th>
<th colspan="4">
Project:
<asp:Label ID="Project_lab" runat="server"></asp:Label></th>
</tr>
<tr>
<th></th>
<th>
CODE
</th>
<th>
DESCRIPTION
</th>
<th>
LENGTH
</th>
<th>
WIDTH
</th>
<th>
QTY
</th>
<th>
COST
</th>
<th>
£M2
</th>
<th>
£UNIT
</th>
<th>
SUPPLIER</th>
<th>
QTY</th>
<th>
DUE DATE</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="ChkItem" runat="server" /></td>
<td style="width: 150px">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Code") %>'></asp:Label></td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Description") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label5" runat="server" Text='<%# Eval("Length") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label6" runat="server" Text='<%# Eval("Width") %>'></asp:Label></td>
<td align="center">
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Qty") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label4" runat="server" Text='<%# Eval("Cost") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label7" runat="server" Text='<%# Eval("M2") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label8" runat="server" Text='<%# Eval("SHT") %>'></asp:Label></td>
<td>
<asp:DropDownList ID="DD1" Width="100%" runat="server" Font-Names="Verdana" Font-Size="8pt">
</asp:DropDownList></td>
<td align="left">
<asp:TextBox ID="Qty_Txt1" OnTextChanged="GetData" OnDataBinding='<%# Eval("Code") %>'
AutoPostBack="true" Width="80%" Font-Names="Verdana" Font-Size="8pt" runat="server"></asp:TextBox></td>
<td>
<asp:TextBox ID="Date1" Width="90%" Font-Names="Verdana" Font-Size="8pt" AutoPostBack="true" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td align="center">
<b>
<asp:Label ID="New_Lab" Font-Size="8pt" runat="Server"></asp:Label></b></td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<asp:DropDownList ID="DD2" Width="100%" Font-Names="Verdana" Font-Size="8pt" runat="server">
</asp:DropDownList></td>
<td align="left">
<asp:TextBox ID="Qty_Txt2" AutoPostBack="true" Width="80%" Font-Names="Verdana"
Font-Size="8pt" runat="Server"></asp:TextBox></td>
<td>
<asp:TextBox ID="Date2" Width="90%" Font-Names="Verdana" Font-Size="8pt" runat="Server"></asp:TextBox></td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<asp:DropDownList ID="DD3" Width="100%" Font-Names="Verdana" Font-Size="8pt" runat="server">
</asp:DropDownList></td>
<td align="left">
<asp:TextBox ID="Qty_Txt3" AutoPostBack="true" Width="80%" Font-Names="Verdana"
Font-Size="8pt" runat="Server"></asp:TextBox></td>
<td width="8%">
<asp:TextBox ID="Date3" Width="90%" Font-Names="Verdana" Font-Size="8pt" runat="Server" ValidationGroup="PersonalInfoGroup">
</asp:TextBox>
<asp:CustomValidator id="RequiredFieldValidator1"
controltovalidate="Date3"
OnServerValidate="Date3_Validator"
errormessage="Date Error!"
runat="Server">
</asp:CustomValidator></td>
</tr>
<asp:HiddenField ID="Supplier" Value='<%# Eval("cdf_supplier_tx") %>' runat="server" />
<asp:HiddenField ID="PrefSupplier" Value='<%# Eval("cdf_supplier_pref") %>' runat="server" />
<asp:HiddenField ID="Nominal" Value='<%# Eval("Nominal") %>' runat="server" />
<asp:HiddenField ID="QuoteCost" Value='<%# Eval("QuoteCost") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<SeparatorStyle BackColor="#C0FFFF" />
<SeparatorTemplate>
</SeparatorTemplate>
</asp:DataList>
EDIT: Some of the VB that's been tried and tested & A little of my own that G_Wilson has tried helping me with but i can't grasp on.
Protected Sub Save_Btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save_Btn.Click
'connection.Open()
'command = New SqlCommand("Select * from impsod_h where [Quote Number]='" + HiddenQno.Value + "'", connection)
'datareader = command.ExecuteReader()
'If datareader.HasRows = False Then
' datareader.Close()
' CreateImpsod1()
' CreateIMPSOH1()
' installcalc()
'Else
' datareader.Close()
'End If
'connection.Close()
For Each Row As GridViewRow In GridView1.Rows
Dim ThisCheck As String
ThisCheck = ChkItem.Checked
Next
End Sub
What i think you will need is a For Each Loop.
That will look a little something like this :
For Each Row as GridViewRow in GridView1.Rows
Dim chkSelect as CheckBox
chkSelect = e.Row.FindControl("ChkItem")
If chkSelect.Checked = True Then
'Put vb.net logic here ...
Else
'Put anything else here ...
End If
Next
That should do the trick.

ASP.NET and ListView control having LinkButton

I have 10 questions in my sql database. I get them and print them in Link form using LinkButton. Now i want to generate click event of every question separately.
How to generate OnClick event of LinkButton inside ListView. Please help in easy steps.
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="userid" >
<AlternatingItemTemplate>
<tr style="">
<td>
<%-- <asp:Label ID="qtLabel" runat="server" Text='<%# Eval("qt") %>' />
--%>
<h3> <asp:LinkButton CommandArgument='<%# Eval("userid") %>' ID="LinkButton1" runat="server"><%# Eval("qt") %></asp:LinkButton> </h3>
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:TextBox ID="qtTextBox" runat="server" Text='<%# Bind("qt") %>' />
</td>
<td>
<asp:Label ID="useridLabel1" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="qtTextBox" runat="server" Text='<%# Bind("qt") %>' />
</td>
<td>
<asp:TextBox ID="useridTextBox" runat="server" Text='<%# Bind("userid") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<h3> <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("userid") %>' runat="server"><%# Eval("qt") %></asp:LinkButton> </h3>
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">qt</th>
<th runat="server">userid</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="qtLabel" runat="server" Text='<%# Eval("qt") %>' />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>" SelectCommand="SELECT [qt], [userid] FROM [java]"></asp:SqlDataSource>
ASPX:
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"
DataKeyNames="userid" onitemcommand="ListView1_ItemCommand" >
<AlternatingItemTemplate>
<tr style="">
<td>
<%-- <asp:Label ID="qtLabel" runat="server" Text='<%# Eval("qt") %>' />
--%>
<h3> <asp:LinkButton CommandArgument='<%# Eval("userid") %>' ID="LinkButton1" runat="server"><%# Eval("qt") %></asp:LinkButton> </h3>
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:TextBox ID="qtTextBox" runat="server" Text='<%# Bind("qt") %>' />
</td>
<td>
<asp:Label ID="useridLabel1" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="qtTextBox" runat="server" Text='<%# Bind("qt") %>' />
</td>
<td>
<asp:TextBox ID="useridTextBox" runat="server" Text='<%# Bind("userid") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<h3> <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("userid") %>' runat="server"><%# Eval("qt") %></asp:LinkButton> </h3>
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">qt</th>
<th id="Th2" runat="server">userid</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="qtLabel" runat="server" Text='<%# Eval("qt") %>' />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"
SelectCommand="SELECT [qt], [userid] FROM [java]"></asp:SqlDataSource>
Code Behind:
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
string userid = e.CommandArgument.ToString();
Response.Write("U:" + userid);
if (userid == "USER_3730")
{
Response.Redirect("bnbnbnbnbn.aspx");
}
if (userid == "USER_b163")
{
Response.Redirect("home.aspx");
}
}

how to prevent postback on click of button in listview

I have a listview.I want to prevent loading of page again and again on click of edit,update and delete. When i click on edit to edit a row the page performs postback.So what i need to do in order to perform no postback.
My code is
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "TestOrigin.aspx/BindDatatable",
data: "{}",
dataType: "json"
});
});
</script>
<script type="text/javascript">
function javascriptfunction()
{
return false;
}
</script>
<asp:ListView ID="lstOrigin"
runat="server"
ItemPlaceholderID="PlaceHolder1" OnItemEditing="EditListViewItem"
OnItemCanceling="CancelListViewItem"
OnItemUpdating="UpdateListViewItem"
OnItemInserting="InsertListViewItem"
InsertItemPosition="LastItem" OnItemDeleting="DeleteListViewItem"
DataKeyNames="ID" >
<LayoutTemplate>
<table width="100%" cellpadding="4" cellspacing="0">
<tr class="header">
<th >
<asp:LinkButton ID="lnkID" runat="server" CommandName="Sort"
CommandArgument="ID" Text="ID" />
</th>
<th >
<asp:LinkButton ID="lnkaddress" runat="server"
CommandName="Sort" CommandArgument="Address" Text="Address" />
</th>
<th >
<asp:LinkButton ID="lnkpin" runat="server" CommandName="Sort"
CommandArgument="Pin" Text="Pin" />
</th>
<th >
<asp:LinkButton ID="lnkcity" runat="server" CommandName="Sort"
CommandArgument="City" Text="City" />
</th>
<th>
<asp:LinkButton ID="lnkstate" runat="server" CommandName="Sort"
CommandArgument="State" Text="State" />
</th>
<th>
<asp:LinkButton ID="lnkcountry" runat="server" CommandName="Sort"
CommandArgument="Country" Text="Country" />
</th>
<th>
<asp:LinkButton ID="lnkport" runat="server" CommandName="Sort"
CommandArgument="Port" Text="Port" />
</th>
<th>
<asp:LinkButton ID="lnkoutsource" runat="server" CommandName="Sort"
CommandArgument="Outsourcing" Text="Outsourcing" />
</th>
<th>
Modify
</th>
</tr>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="item">
<td>
<%# Eval("ID") %>
</td>
<td>
<%# Eval("Address") %>
</td>
<td>
<%# Eval("Pin") %>
</td>
<td>
<%# Eval("City") %>
</td>
<td>
<%# Eval("State") %>
</td>
<td>
<%# Eval("Country") %>
</td>
<td>
<%# Eval("Port") %>
</td>
<td>
<%# Eval("Outsourcing") %>
</td>
<td>
<asp:Button ID="lnkEdit" runat="server" Text="Edit"
PostBackUrl="~/TestOrigin.aspx" CommandName="Edit" OnClientClick="javascriptfunction"/>
<asp:Button ID="lnkDelete" runat="server" Text="Delete"
CommandName="Delete" ForeColor="Brown" OnClientClick="javascriptfunction"/>
</span>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td>
<%# Eval("ID") %>
</td>
<td>
<%# Eval("Address") %>
</td>
<td>
<%# Eval("Pin") %>
</td>
<td>
<%# Eval("City") %>
</td>
<td>
<%# Eval("State") %>
</td>
<td>
<%# Eval("Country") %>
</td>
<td>
<%# Eval("Port") %>
</td>
<td>
<%# Eval("Outsourcing") %>
</td>
<td>
<asp:Button ID="lnkEdit" runat="server" Text="Edit"
CommandName="Edit" OnClientClick="javascriptfunction" />
<asp:Button ID="lnkDelete" runat="server" Text="Delete"
CommandName="Delete" ForeColor="Brown" OnClientClick="javascriptfunction"/>
</span>
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr class="edititem">
<td>
<asp:TextBox ID="txtID" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:TextBox ID="txtAddress" runat="server" Text='<%#
Eval("Address") %>' />
</td>
<td>
<asp:TextBox ID="txtPin" runat="server" Text='<%# Eval("Pin") %>'
/>
</td>
<td>
<asp:TextBox ID="txtCity" runat="server" Text='<%# Eval("City") %>'
/>
</td>
<td>
<asp:TextBox ID="txtState" runat="server" Text='<%# Eval("State")
%>' />
</td>
<td>
<asp:TextBox ID="txtCountry" runat="server" Text='<%#
Eval("Country") %>' />
</td>
<td>
<asp:TextBox ID="txtPort" runat="server" Text='<%# Eval("Port") %>'
/>
</td>
<td>
<asp:TextBox ID="txtOutsource" runat="server" Text='<%#
Eval("Outsourcing") %>' />
</td>
<td>
<asp:Button ID="btnUpdate" runat="server" Text="Update"
CommandName="Update" OnClientClick=" javascriptfunction" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel"
CommandName="Cancel" OnClientClick=" javascriptfunction" />
</td>
</tr>
</EditItemTemplate>
</EmptyDataTemplate>
</asp:ListView>
put return before your function
OnClientClick="return javascriptfunction()"
and in java-script function at the end write
return false;

AlternateTemplate is not working for Listview

I modified Listview as per my need,but now is not working, in means, its showing row with different color but repeating same data. And then coming next data, againg its repeating and going on.... Here I am lisitng my code.
for Example,
1
1 (Repeating, Different Color row)
2
2 (Repeating, Different Color row)
3
3 (Repeating, Different Color row)
.
.
.
.
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="uniqueno">
<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;" runat="server">
<td>
<asp:Label ID="policeNumLabel" runat="server" Text='<%# Eval("policeNum") %>' />
</td>
<td>
<asp:Label ID="DFirstNameLabel" runat="server" Text='<%# String.Format("{0} {1} {2}", Eval("DFirstName"),Eval("DMidName"),Eval("DSurName")) %>' />
</td>
<td>
<asp:Label ID="DLicenceNoLabel" runat="server"
Text='<%# Eval("DLicenceNo") %>' />
</td>
<td>
<asp:Label ID="ManufacturerLabel" runat="server"
Text='<%# Eval("Manufacturer") %>' />
</td>
<td>
<asp:Label ID="SerialNumLabel" runat="server" Text='<%# Eval("SerialNum") %>' />
</td>
<td>
<asp:Label ID="ModelLabel" runat="server" Text='<%# Eval("Model") %>' />
</td>
<td>
<asp:Label ID="CalibreLabel" runat="server" Text='<%# Eval("Calibre") %>' />
</td>
<td>
<asp:Label ID="TypeLabel" runat="server" Text='<%# Eval("Type") %>' />
</td>
<td>
<asp:Label ID="ActionLabel" runat="server" Text='<%# Eval("Action") %>' />
</td>
<td>
<asp:Label ID="BarrelLengthLabel" runat="server"
Text='<%# Eval("BarrelLength") %>' />
</td>
<td>
<asp:Label ID="ReasonLabel" runat="server" Text='<%# Eval("Reason") %>' />
</td>
<td>
<asp:Label ID="OtherLabel" runat="server" Text='<%# Eval("Other") %>' />
</td>
<td>
<asp:Label ID="TransferPendingLabel" runat="server" Text='<%# Eval("TransferPending") %>' />
</td>
<td>
<asp:Label ID="OFirstNameLabel" runat="server"
Text='<%# String.Format("{0} {1} {2}", Eval("OFirstName"),Eval("OmidName"),Eval("OSurName")) %>' />
</td>
<td>
<asp:Label ID="O_LicenceNoLabel" runat="server"
Text='<%# Eval("O_LicenceNo") %>' />
</td>
<td>
<asp:Label ID="DateAcqLabel" runat="server" Text='<%# Eval("DateAcq") %>' />
</td>
<td>
<asp:Label ID="Dis_FirstnameLabel" runat="server"
Text='<%# String.Format("{0} {1} {2}",Eval("Dis_Firstname"),Eval("Dis_Midname"),Eval("Dis_Surname")) %>' />
</td>
<td>
<asp:Label ID="Dis_LicenceNoLabel" runat="server"
Text='<%# Eval("Dis_LicenceNo") %>' />
</td>
<td>
<asp:Label ID="Dis_DisposaldateLabe" runat="server"
Text='<%# Eval("Dis_Disposaldate") %>' />
</td>
<td>
<asp:Label ID="Dis_CommentLabel" runat="server"
Text='<%# Eval("Dis_Comment") %>' />
</td>
<td>
<asp:Label ID="PermittoAcqNoLabel" runat="server" Text='<%# Eval("PermittoAcqNo") %>' />
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr id="Tr1" style="background-color:#DCDCDC;color: #000000;" runat="server">
<td>
<asp:Label ID="policeNumLabel" runat="server" Text='<%# Eval("policeNum") %>' />
</td>
<td>
<asp:Label ID="DFirstNameLabel" runat="server" Text='<%# String.Format("{0} {1} {2}", Eval("DFirstName"),Eval("DMidName"),Eval("DSurName")) %>' />
</td>
<td>
<asp:Label ID="DLicenceNoLabel" runat="server"
Text='<%# Eval("DLicenceNo") %>' />
</td>
<td>
<asp:Label ID="ManufacturerLabel" runat="server"
Text='<%# Eval("Manufacturer") %>' />
</td>
<td>
<asp:Label ID="SerialNumLabel" runat="server" Text='<%# Eval("SerialNum") %>' />
</td>
<td>
<asp:Label ID="ModelLabel" runat="server" Text='<%# Eval("Model") %>' />
</td>
<td>
<asp:Label ID="CalibreLabel" runat="server" Text='<%# Eval("Calibre") %>' />
</td>
<td>
<asp:Label ID="TypeLabel" runat="server" Text='<%# Eval("Type") %>' />
</td>
<td>
<asp:Label ID="ActionLabel" runat="server" Text='<%# Eval("Action") %>' />
</td>
<td>
<asp:Label ID="BarrelLengthLabel" runat="server"
Text='<%# Eval("BarrelLength") %>' />
</td>
<td>
<asp:Label ID="ReasonLabel" runat="server" Text='<%# Eval("Reason") %>' />
</td>
<td>
<asp:Label ID="OtherLabel" runat="server" Text='<%# Eval("Other") %>' />
</td>
<td>
<asp:Label ID="TransferPendingLabel" runat="server" Text='<%# Eval("TransferPending") %>' />
</td>
<td>
<asp:Label ID="OFirstNameLabel" runat="server"
Text='<%# String.Format("{0} {1} {2}", Eval("OFirstName"),Eval("OmidName"),Eval("OSurName")) %>' />
</td>
<td>
<asp:Label ID="O_LicenceNoLabel" runat="server"
Text='<%# Eval("O_LicenceNo") %>' />
</td>
<td>
<asp:Label ID="DateAcqLabel" runat="server" Text='<%# Eval("DateAcq") %>' />
</td>
<td>
<asp:Label ID="Dis_FirstnameLabel" runat="server"
Text='<%# String.Format("{0} {1} {2}",Eval("Dis_Firstname"),Eval("Dis_Midname"),Eval("Dis_Surname")) %>' />
</td>
<td>
<asp:Label ID="Dis_LicenceNoLabel" runat="server"
Text='<%# Eval("Dis_LicenceNo") %>' />
</td>
<td>
<asp:Label ID="Dis_DisposaldateLabe" runat="server"
Text='<%# Eval("Dis_Disposaldate") %>' />
</td>
<td>
<asp:Label ID="Dis_CommentLabel" runat="server"
Text='<%# Eval("Dis_Comment") %>' />
</td>
<td>
<asp:Label ID="PermittoAcqNoLabel" runat="server" Text='<%# Eval("PermittoAcqNo") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<table runat="server"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<tr>
<td>
No data found</td>
</tr>
</table>
</EmptyDataTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="1"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr runat="server" >
<th colspan="3" runat="server">Dealer Info </th>
<th colspan="7" runat="server">Firearm Details </th>
<th colspan="3" runat="server">Reason </th>
<th colspan="3" runat="server">Acquisition Details </th>
<th colspan="5" runat="server">Disposal Details </th>
</tr>
<tr runat="server" style="background-color:#DCDCDC;color: #000000;">
<th runat="server">Number</th>
<th runat="server">Name</th>
<th runat="server">Licence #</th>
<th runat="server">Manufacturer</th>
<th runat="server">Serial #</th>
<th runat="server">Model</th>
<th runat="server">Calibre</th>
<th runat="server">Type</th>
<th runat="server">Action</th>
<th runat="server">Barrel Length</th>
<th runat="server">Reason</th>
<th runat="server">Other</th>
<th runat="server">Transfer Pending</th>
<th runat="server">Name</th>
<th runat="server">Licence #</th>
<th runat="server">Date of Acquired</th>
<th runat="server">Name</th>
<th runat="server">Licence #</th>
<th runat="server">Date of Disposal</th>
<th runat="server">Comment</th>
<th runat="server">Permit to Acquire No</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server"
style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
<td>
<asp:Label ID="policeNumLabel" runat="server" Text='<%# Eval("policeNum") %>' />
</td>
<td>
<asp:Label ID="DFirstNameLabel" runat="server"
Text='<%# Eval("DFirstName") %>' />
</td>
<td>
<asp:Label ID="DMidNameLabel" runat="server" Text='<%# Eval("DMidName") %>' />
</td>
<td>
<asp:Label ID="DSurNameLabel" runat="server" Text='<%# Eval("DSurName") %>' />
</td>
<td>
<asp:Label ID="DLicenceNoLabel" runat="server"
Text='<%# Eval("DLicenceNo") %>' />
</td>
<td>
<asp:Label ID="Dis_DisposaldateLabel" runat="server"
Text='<%# Eval("Dis_Disposaldate") %>' />
</td>
<td>
<asp:Label ID="SerialNumLabel" runat="server" Text='<%# Eval("SerialNum") %>' />
</td>
<td>
<asp:Label ID="CalibreLabel" runat="server" Text='<%# Eval("Calibre") %>' />
</td>
<td>
<asp:Label ID="BarrelLengthLabel" runat="server"
Text='<%# Eval("BarrelLength") %>' />
</td>
<td>
<asp:Label ID="ManufacturerLabel" runat="server"
Text='<%# Eval("Manufacturer") %>' />
</td>
<td>
<asp:Label ID="OtherLabel" runat="server" Text='<%# Eval("Other") %>' />
</td>
<td>
<asp:Label ID="ModelLabel" runat="server" Text='<%# Eval("Model") %>' />
</td>
<td>
<asp:Label ID="TypeLabel" runat="server" Text='<%# Eval("Type") %>' />
</td>
<td>
<asp:Label ID="ActionLabel" runat="server" Text='<%# Eval("Action") %>' />
</td>
<td>
<asp:Label ID="TransferPendingLabel" runat="server"
Text='<%# Eval("TransferPending") %>' />
</td>
<td>
<asp:Label ID="DateAcqLabel" runat="server" Text='<%# Eval("DateAcq") %>' />
</td>
<td>
<asp:Label ID="OFirstNameLabel" runat="server"
Text='<%# Eval("OFirstName") %>' />
</td>
<td>
<asp:Label ID="OmidNameLabel" runat="server" Text='<%# Eval("OmidName") %>' />
</td>
<td>
<asp:Label ID="OSurNameLabel" runat="server" Text='<%# Eval("OSurName") %>' />
</td>
<td>
<asp:Label ID="O_LicenceNoLabel" runat="server"
Text='<%# Eval("O_LicenceNo") %>' />
</td>
<td>
<asp:Label ID="DNoLabel" runat="server" Text='<%# Eval("DNo") %>' />
</td>
<td>
<asp:Label ID="StreetLabel" runat="server" Text='<%# Eval("Street") %>' />
</td>
<td>
<asp:Label ID="column1Label" runat="server" Text='<%# Eval("column1") %>' />
</td>
<td>
<asp:Label ID="StateLabel" runat="server" Text='<%# Eval("State") %>' />
</td>
<td>
<asp:Label ID="PostCodeLabel" runat="server" Text='<%# Eval("PostCode") %>' />
</td>
<td>
<asp:Label ID="PermittoAcqNoLabel" runat="server"
Text='<%# Eval("PermittoAcqNo") %>' />
</td>
<td>
<asp:Label ID="Dis_FirstnameLabel" runat="server"
Text='<%# Eval("Dis_Firstname") %>' />
</td>
<td>
<asp:Label ID="Dis_MidnameLabel" runat="server"
Text='<%# Eval("Dis_Midname") %>' />
</td>
<td>
<asp:Label ID="Dis_SurnameLabel" runat="server"
Text='<%# Eval("Dis_Surname") %>' />
</td>
<td>
<asp:Label ID="Dis_LicenceNoLabel" runat="server"
Text='<%# Eval("Dis_LicenceNo") %>' />
</td>
<td>
<asp:Label ID="Dis_DnoLabel" runat="server" Text='<%# Eval("Dis_Dno") %>' />
</td>
<td>
<asp:Label ID="Dis_StreetLabel" runat="server"
Text='<%# Eval("Dis_Street") %>' />
</td>
<td>
<asp:Label ID="column2Label" runat="server" Text='<%# Eval("column2") %>' />
</td>
<td>
<asp:Label ID="Dis_stateLabel" runat="server" Text='<%# Eval("Dis_state") %>' />
</td>
<td>
<asp:Label ID="Dis_postcodeLabel" runat="server"
Text='<%# Eval("Dis_postcode") %>' />
</td>
<td>
<asp:Label ID="Dis_CommentLabel" runat="server"
Text='<%# Eval("Dis_Comment") %>' />
</td>
<td>
<asp:Label ID="ReasonLabel" runat="server" Text='<%# Eval("Reason") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
There was no fault with code....
After having lots of experiment, I realise that there something wrong with my Database, and that's what happened, there was duplicate existed which were removed and now listview is work fine.

Resources