ASP.NET and ListView control having LinkButton - asp.net

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

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>

Fix datalist single item layout while printing

I have a datalist where i m displaying 8 items for printing.I m printing two items per row.When i print a two or more than two items,the layout is perfect.but when i print single item.the layout changes and expands.How Can i fix it for single item also.
<asp:DataList ID="datalis1" runat="server" RepeatDirection="Horizontal"
BorderStyle="NotSet" CellPadding="0" CellSpacing="5" RepeatLayout="Table"
RepeatColumns="2" >
<ItemStyle />
<ItemTemplate>
<asp:Panel ID="Panel1" runat="server" CssClass="boxdiv">
<table style="width: 94%;" align="center" cellspacing="0" cellpadding="0" border="0" class="table1">
<tr style="height:2px;">
<td colspan="0" rowspan="0" height='2px'>
<asp:Label ID="lblwebsite" runat="server" Font-Bold="True" Text='<% # bind("website")%>'>
</asp:Label>
</td>
</tr>
<tr style="height:2px;" >
<td colspan="0" rowspan="0" height='2px'>
<asp:Label ID="Label13" runat="server" Font-Bold="True" Text="Call #">
</asp:Label>
<asp:Label ID="lblcontact" runat="server" Text='<% # bind("mobile1")%>'>
</asp:Label>
<asp:Label ID="Label15" runat="server" Font-Bold="True" Text="Fax #">
</asp:Label>
<asp:Label ID="lblfax" runat="server" Text='<% # bind("fax")%>'>
</asp:Label>
</td>
</tr>
<tr style="height:2px;">
<td colspan="0" rowspan="0" height='2px' >
<%--<asp:Label ID="lblfax0" runat="server" Font-Bold="True" Text="Address :">
</asp:Label>--%>
<asp:Label ID="lbladdress" runat="server" Text='<% # bind("address")%>' ></asp:Label>
</td>
</tr>
<tr style="height:4px;">
</tr>
<tr style="height:4px;">
</tr>
<tr style="height:2px;">
<td height='2px' >
<asp:Label ID="lblfax1" runat="server" Font-Bold="True" Text="Ord #">
</asp:Label>
<asp:Label ID="lblorder" runat="server" text='<% # bind("orderno")%>'>
</asp:Label>
<asp:Label ID="lblfax2" runat="server" Font-Bold="True" Text="Dt:">
</asp:Label>
<asp:Label ID="lblvrdate" runat="server" Text='<% # bind("vr_date")%>'>
</asp:Label>
</td>
</tr>
<tr >
<td height='2px' >
<asp:Label ID="lblfax3" runat="server" Font-Bold="True" Text="Pt:">
</asp:Label>
<asp:Label ID="lblpt" runat="server" Text='<% # bind("pname")%>' Font-Bold="False" >
</asp:Label>
<asp:Label ID="Label16" runat="server" Font-Bold="True" Text="Dr :">
</asp:Label>
<asp:Label ID="lbldrname" Text='<% # bind("drname")%>' runat="server" Font-Bold="False" >
</asp:Label>
</td>
</tr>
<tr style="height:4px;" >
</tr>
<tr style="height:4px;" >
</tr>
<tr >
<td height='2px'>
<asp:Label ID="Label17" runat="server" Font-Bold="True"
Text="Rx:"></asp:Label>
<asp:Label ID="lblorderSupplied" runat="server" Font-Bold="False" Text='<% # bind("medicine")%>'
></asp:Label> <br />
<asp:Label ID="labeld" runat="server" Text="Qty:" Font-Bold="True"></asp:Label>
<asp:Label ID="lblpack" Text='<% # bind("pack")%>' runat="server" ></asp:Label>
<asp:Label ID="txtmfgDt" runat="server" text="x"> </asp:Label>
<asp:Label ID="lblqty" runat="server" text='<% # bind("suppquantity")%>'></asp:Label>
</td>
</tr>
<tr style="height:4px;" >
</tr>
<tr style="height:4px;" >
</tr>
<tr >
<td height='2px'>
<%-- <asp:Label ID="Label18" runat="server" Font-Bold="True"
Text="Directions:"></asp:Label>--%>
<%-- <div style="text-overflow : ellipsis; overflow: hidden; overflow-y: hidden; height:38px">--%>
<asp:Label ID="lbldirections" Height="38PX" Text='<% # bind("directions")%>' runat="server" Font-Bold="False"></asp:Label>
<%-- </div>--%>
</td>
</tr>
<tr >
<td height='2px'>
<%-- <asp:Label ID="lblmfg" runat="server" text="Mfg:"></asp:Label>--%>
</td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</asp:DataList>

Paging data from access with SEO friendly urls

I need some help about how to paging data from access data base.
I used asp:ListView and asp:DataPager like some example I found but the paging work with javascript and I want the paging will be friendly.
How I can put some of my code?
[edit]
this is the code:
<asp:ListView ID="tblProjects" runat="server" OnPagePropertiesChanging="tblProjects_PagePropertiesChanging">
<LayoutTemplate>
<ul class="ulProducts">
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<div class="divProduct">
<a rel='pics' href='GalleryEditor/pictures/<%# Eval("BigImageName") %>'>
<img src='GalleryEditor/pictures/<%# Eval("SmallImagesName") %>'
alt='<%# Eval("ImageDetail") %>' title='<%# Eval("ImageDetail") %>' />
</a>
</div>
</li>
</ItemTemplate>
<EmptyDataTemplate>
no data
</EmptyDataTemplate>
This the code behind:
protected void tblProjects_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
//set current page startindex, max rows and rebind to false
imagesPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
string page = Request.QueryString["p"];
if (!(FormValidator.IsNumber(page)))
page = "8800";
buildProducts(page);
}
void buildTitleAndDescription(string page)
{
// set page title
OleDbConnection conn0 = new OleDbConnection(#"Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath("GalleryEditor\\App_Data\\projects.mdb"));
OleDbCommand comm0 = new OleDbCommand("select ProjectName from Project where PlaceID=" + page, conn0);
OleDbDataReader reader0;
conn0.Open();
reader0 = comm0.ExecuteReader();
reader0.Read();
Page.Header.Title = reader0["ProjectName"].ToString();
reader0.Close();
conn0.Close();
//if (IsPostBack)
//{
// string Script = "<script type='text/javascript'>goToEnd();\n</script>";
// Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", Script);
//}
}
void buildProducts(string page)
{
// set page content
OleDbConnection conn = new OleDbConnection(#"Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath("GalleryEditor\\App_Data\\sb.mdb"));
OleDbCommand comm = new OleDbCommand("select SmallImagesName, BigImageName, ImageDetail from Images where PlaceID=" + page, conn);
conn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(comm);
da.Fill(ds);
tblProjects.DataSource = ds;
tblProjects.DataBind();
}
I do not mind change the code to better one and if I learn form it I will appreciate it.
All the example I found is for SQL and my data need to be on access.
Here is an example of asp listview you will have to define the querystring as follows.
<asp:ListView ID="ListView1" runat="server" DataKeyNames="bd_book_code"
DataSourceID="SqlDataSource1" EnableModelValidation="True">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="bd_book_codeLabel" runat="server"
Text='<%# Eval("bd_book_code") %>' />
</td>
<td>
<asp:Label ID="bd_isbnLabel" runat="server" Text='<%# Eval("bd_isbn") %>' />
</td>
<td>
<asp:Label ID="bd_titleLabel" runat="server" Text='<%# Eval("bd_title") %>' />
</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="bd_book_codeLabel1" runat="server"
Text='<%# Eval("bd_book_code") %>' />
</td>
<td>
<asp:TextBox ID="bd_isbnTextBox" runat="server" Text='<%# Bind("bd_isbn") %>' />
</td>
<td>
<asp:TextBox ID="bd_titleTextBox" runat="server"
Text='<%# Bind("bd_title") %>' />
</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="bd_book_codeTextBox" runat="server"
Text='<%# Bind("bd_book_code") %>' />
</td>
<td>
<asp:TextBox ID="bd_isbnTextBox" runat="server" Text='<%# Bind("bd_isbn") %>' />
</td>
<td>
<asp:TextBox ID="bd_titleTextBox" runat="server"
Text='<%# Bind("bd_title") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="bd_book_codeLabel" runat="server"
Text='<%# Eval("bd_book_code") %>' />
</td>
<td>
<asp:Label ID="bd_isbnLabel" runat="server" Text='<%# Eval("bd_isbn") %>' />
</td>
<td>
<asp:Label ID="bd_titleLabel" runat="server" Text='<%# Eval("bd_title") %>' />
</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">
bd_book_code</th>
<th runat="server">
bd_isbn</th>
<th runat="server">
bd_title</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server" QueryStringField="pid">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="bd_book_codeLabel" runat="server"
Text='<%# Eval("bd_book_code") %>' />
</td>
<td>
<asp:Label ID="bd_isbnLabel" runat="server" Text='<%# Eval("bd_isbn") %>' />
</td>
<td>
<asp:Label ID="bd_titleLabel" runat="server" Text='<%# Eval("bd_title") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
QueryStringField="pid" will do the magic.

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