how to prevent postback on click of button in listview - asp.net

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;

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>

Datatables not working when having nested asp:ListView?

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": ""
}]

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");
}
}

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.

how to make a new button in ListView?

I need to make an image button in the layout template of ListView,
when i click on the button it should open the insert template so i can insert a new record
here is my ListView:
<asp:ListView ID="LVCategories" runat="server" DataKeyNames="CatID" DataSourceID="CategoriesDS" EnableModelValidation="True">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="CatIDLabel" runat="server" Text='<%# Eval("CatID") %>' />
</td>
<td>
<asp:Label ID="CatTitleLabel" runat="server" Text='<%# Eval("CatTitle") %>' />
</td>
<td>
<asp:Label ID="CatDescriptionLabel" runat="server" Text='<%# Eval("CatDescription") %>' />
</td>
<td>
<asp:Label ID="CatTitleArLabel" runat="server" Text='<%# Eval("CatTitleAr") %>' />
</td>
<td>
<asp:Label ID="CatDescriptionArLabel" runat="server" Text='<%# Eval("CatDescriptionAr") %>' />
</td>
<td>
<asp:Label ID="PictureIDLabel" runat="server" Text='<%# Eval("PictureID") %>' />
</td>
<td>
<asp:CheckBox ID="PublishedCheckBox" runat="server" Checked='<%# Eval("Published") %>' Enabled="false" />
</td>
<td>
<asp:Label ID="DisplayOrderLabel" runat="server" Text='<%# Eval("DisplayOrder") %>' />
</td>
<td>
<asp:Label ID="CreatedOnLabel" runat="server" Text='<%# Eval("CreatedOn") %>' />
</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:Label ID="CatIDLabel1" runat="server" Text='<%# Eval("CatID") %>' />
</td>
<td>
<asp:TextBox ID="CatTitleTextBox" runat="server" Text='<%# Bind("CatTitle") %>' />
</td>
<td>
<asp:TextBox ID="CatDescriptionTextBox" runat="server" Text='<%# Bind("CatDescription") %>' />
</td>
<td>
<asp:TextBox ID="CatTitleArTextBox" runat="server" ext='<%# Bind("CatTitleAr") %>' />
</td>
<td>
<asp:TextBox ID="CatDescriptionArTextBox" runat="server" Text='<%# Bind("CatDescriptionAr") %>' />
</td>
<td>
<asp:TextBox ID="PictureIDTextBox" runat="server" Text='<%# Bind("PictureID") %>' />
</td>
<td>
<asp:CheckBox ID="PublishedCheckBox" runat="server" Checked='<%# Bind("Published") %>' />
</td>
<td>
<asp:TextBox ID="DisplayOrderTextBox" runat="server" Text='<%# Bind("DisplayOrder") %>' />
</td>
<td>
<asp:TextBox ID="CreatedOnTextBox" runat="server" Text='<%# Bind("CreatedOn") %>' />
</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="CatIDTextBox" runat="server" Text='<%# Bind("CatID") %>' />
</td>
<td>
<asp:TextBox ID="CatTitleTextBox" runat="server" Text='<%# Bind("CatTitle") %>' />
</td>
<td>
<asp:TextBox ID="CatDescriptionTextBox" runat="server" Text='<%# Bind("CatDescription") %>' />
</td>
<td>
<asp:TextBox ID="CatTitleArTextBox" runat="server" Text='<%# Bind("CatTitleAr") %>' />
</td>
<td>
<asp:TextBox ID="CatDescriptionArTextBox" runat="server" Text='<%# Bind("CatDescriptionAr") %>' />
</td>
<td>
<asp:TextBox ID="PictureIDTextBox" runat="server" Text='<%# Bind("PictureID") %>' />
</td>
<td>
<asp:CheckBox ID="PublishedCheckBox" runat="server" Checked='<%# Bind("Published") %>' />
</td>
<td>
<asp:TextBox ID="DisplayOrderTextBox" runat="server" Text='<%# Bind("DisplayOrder") %>' />
</td>
<td>
<asp:TextBox ID="CreatedOnTextBox" runat="server" Text='<%# Bind("CreatedOn") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="CatIDLabel" runat="server" Text='<%# Eval("CatID") %>' />
</td>
<td>
<asp:Label ID="CatTitleLabel" runat="server" Text='<%# Eval("CatTitle") %>' />
</td>
<td>
<asp:Label ID="CatDescriptionLabel" runat="server" Text='<%# Eval("CatDescription") %>' />
</td>
<td>
<asp:Label ID="CatTitleArLabel" runat="server" Text='<%# Eval("CatTitleAr") %>' />
</td>
<td>
<asp:Label ID="CatDescriptionArLabel" runat="server" Text='<%# Eval("CatDescriptionAr") %>' />
</td>
<td>
<asp:Label ID="PictureIDLabel" runat="server" Text='<%# Eval("PictureID") %>' />
</td>
<td>
<asp:CheckBox ID="PublishedCheckBox" runat="server" Checked='<%# Eval("Published") %>' Enabled="false" />
</td>
<td>
<asp:Label ID="DisplayOrderLabel" runat="server" Text='<%# Eval("DisplayOrder") %>' />
</td>
<td>
<asp:Label ID="CreatedOnLabel" runat="server" Text='<%# Eval("CreatedOn") %>' />
</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">
<asp:ImageButton ID="btnNew" runat="server" CommandName="New" />
<%--<asp:ImageButton ID="NewCatbtn" runat="server" CommandName="Insert" ImageUrl="~/ADMIN/themes/Img/New.png" AlternateText="Click Here To Add New" OnClick="OpenTheInsertTemplates"/>--%>
</th>
<th runat="server">CatTitle</th>
<th runat="server">CatDescription</th>
<th runat="server">CatTitleAr</th>
<th runat="server">atDescriptionAr</th>
<th runat="server">PictureID</th>
<th runat="server">Published</th>
<th runat="server">DisplayOrder</th>
<th runat="server">CreatedOn</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="CatIDLabel" runat="server" Text='<%# Eval("CatID") %>' />
</td>
<td>
<asp:Label ID="CatTitleLabel" runat="server" Text='<%# Eval("CatTitle") %>' />
</td>
<td>
<asp:Label ID="CatDescriptionLabel" runat="server"
Text='<%# Eval("CatDescription") %>' />
</td>
<td>
<asp:Label ID="CatTitleArLabel" runat="server"
Text='<%# Eval("CatTitleAr") %>' />
</td>
<td>
<asp:Label ID="CatDescriptionArLabel" runat="server"
Text='<%# Eval("CatDescriptionAr") %>' />
</td>
<td>
<asp:Label ID="PictureIDLabel" runat="server" Text='<%# Eval("PictureID") %>' />
</td>
<td>
<asp:CheckBox ID="PublishedCheckBox" runat="server"
Checked='<%# Eval("Published") %>' Enabled="false" />
</td>
<td>
<asp:Label ID="DisplayOrderLabel" runat="server"
Text='<%# Eval("DisplayOrder") %>' />
</td>
<td>
<asp:Label ID="CreatedOnLabel" runat="server" Text='<%# Eval("CreatedOn") %>' />
</td>
</tr>
</SelectedItemTemplate>
<asp:Button runat="server" ID="cmdInsert" CommandName="Insert" Text="Insert" />
Protected Sub ListView1_ItemInserting (ByVal sender As Object, ByVal e as ListViewEditEventArgs)
' ... '
End Sub
this example has been solved like this :
ASPX file:
<th runat="server">
<asp:ImageButton ID="ImageButton1" runat="server" Text="new" CommandName="new" ImageUrl="~/ADMIN/themes/Img/DeleteBtn.png" />
</th>
the VB.net Code:
Sub deletedd(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles ListView1.ItemCommand
Try
If e.CommandName.Equals("Delete") Then
'this to take a value from any control
Dim Idlabel As Label = e.Item.FindControl("ImageIDLabel")
Session("ID") = Idlabel.Text()
End If
If e.CommandName.Equals("new") Then
'Other code
ListView1.InsertItemPosition = InsertItemPosition.FirstItem
End If
If e.CommandName.Equals("Cancel") Then
'Other code
ListView1.InsertItemPosition = InsertItemPosition.None
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Resources