listview.aspx:
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<table border="0" cellpadding="1">
<tr style="background-color: #E5E5FE">
<th align="left">
<asp:LinkButton ID="lnkId" runat="server">Id</asp:LinkButton>
</th>
<th align="left">
<asp:LinkButton ID="lnkName" runat="server">PageName</asp:LinkButton>
</th>
<th align="left">
<asp:LinkButton ID="lnkType" runat="server">PageDesc</asp:LinkButton>
</th>
<th>
<asp:LinkButton ID="lnkActive" runat="server">Active</asp:LinkButton>
</th>
<th>
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
<asp:DataPager ID="ItemDataPager" runat="server" PageSize="5">
<Fields>
<asp:NumericPagerField ButtonCount="2" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label runat="server" ID="lblId"><%#Eval("AutoID")%></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblName"><%#Eval("PageName") %></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblType"><%#Eval("PageDescription")%></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblact"><%#Eval("Active")%></asp:Label>
</td>
<td>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color: #EFEFEF">
<td>
<asp:Label runat="server" ID="lblId"><%#Eval("AutoID")%></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblName"><%#Eval("PageName") %></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblType"><%#Eval("PageDescription")%></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblact"><%#Eval("Active")%></asp:Label>
</td>
<td>
</td>
</tr>
</AlternatingItemTemplate>
<InsertItemTemplate>
<tr id="Tr1" runat="server">
<td>
</td>
<td>
<asp:TextBox ID="txtFname" runat="server" Text='<%#Eval("AutoID")%>' Width="100px">First Name</asp:TextBox>
<asp:TextBox ID="txtLname" runat="server" Text='<%#Eval("PageName")%>' Width="100px">Last Name</asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtCtype" runat="server" Text='<%#Eval("PageDescription")%>' Width="100px">Contact Type</asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Active")%>' Width="100px">Contact Type</asp:TextBox>
</td>
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
listview.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class ListView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) { MFIll_DetailViewes(); }
}
private void MFIll_DetailViewes()
{
string strConn = @"Data Source=.\sqlexpress;Initial Catalog=Test;Integrated Security=True";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand cmd = new SqlCommand("select * from mySampleTable", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ListView1.DataSource = ds.Tables[0];
ListView1.DataBind();
}
}
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<table border="0" cellpadding="1">
<tr style="background-color: #E5E5FE">
<th align="left">
<asp:LinkButton ID="lnkId" runat="server">Id</asp:LinkButton>
</th>
<th align="left">
<asp:LinkButton ID="lnkName" runat="server">PageName</asp:LinkButton>
</th>
<th align="left">
<asp:LinkButton ID="lnkType" runat="server">PageDesc</asp:LinkButton>
</th>
<th>
<asp:LinkButton ID="lnkActive" runat="server">Active</asp:LinkButton>
</th>
<th>
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
<asp:DataPager ID="ItemDataPager" runat="server" PageSize="5">
<Fields>
<asp:NumericPagerField ButtonCount="2" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label runat="server" ID="lblId"><%#Eval("AutoID")%></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblName"><%#Eval("PageName") %></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblType"><%#Eval("PageDescription")%></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblact"><%#Eval("Active")%></asp:Label>
</td>
<td>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color: #EFEFEF">
<td>
<asp:Label runat="server" ID="lblId"><%#Eval("AutoID")%></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblName"><%#Eval("PageName") %></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblType"><%#Eval("PageDescription")%></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblact"><%#Eval("Active")%></asp:Label>
</td>
<td>
</td>
</tr>
</AlternatingItemTemplate>
<InsertItemTemplate>
<tr id="Tr1" runat="server">
<td>
</td>
<td>
<asp:TextBox ID="txtFname" runat="server" Text='<%#Eval("AutoID")%>' Width="100px">First Name</asp:TextBox>
<asp:TextBox ID="txtLname" runat="server" Text='<%#Eval("PageName")%>' Width="100px">Last Name</asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtCtype" runat="server" Text='<%#Eval("PageDescription")%>' Width="100px">Contact Type</asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Active")%>' Width="100px">Contact Type</asp:TextBox>
</td>
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
listview.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class ListView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) { MFIll_DetailViewes(); }
}
private void MFIll_DetailViewes()
{
string strConn = @"Data Source=.\sqlexpress;Initial Catalog=Test;Integrated Security=True";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand cmd = new SqlCommand("select * from mySampleTable", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ListView1.DataSource = ds.Tables[0];
ListView1.DataBind();
}
}
No comments:
Post a Comment