<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<,,BE>>>>>>>>>>>>>>>>>>>>>>>>....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BE_test
{
public class BECountry
{
public int CId {get; set;}
public string Country { get; set; }
}
}
---------------------------------------2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BE_test
{
public class BEtest
{
public int Id {get; set;}
public string Name {get; set;}
public string Address {get; set;}
public string City {get; set;}
public string Phoneno {get; set;}
public int CId {get; set;}
public string Country { get; set; }
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>DAl>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE_test;
using System.Data.SqlClient;
using System.Data;
namespace DAl_test
{
public class DALCountry
{
private string connect = MyConnectionString.path;
public List<BECountry> show()
{
List<BECountry> list = new List<BECountry>();
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spcount.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
BECountry becountry = new BECountry();
becountry.CId = Convert.ToInt32(sdr["CId"]);
becountry.Country = Convert.ToString(sdr["Country"]);
list.Add(becountry);
}
}
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
return list;
}
}
}
------------------------------2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE_test;
using System.Data;
using System.Data.SqlClient;
namespace DAl_test
{
public class DAltest
{
private string connect = MyConnectionString.path;
public List<BEtest> show()
{
List<BEtest> list = new List<BEtest>();
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.show.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
BEtest BEtest = new BEtest();
BEtest.Id = Convert.ToInt32(sdr["Id"]);
BEtest.Name = Convert.ToString(sdr["Name"]);
BEtest.Address = Convert.ToString(sdr["Address"]);
BEtest.City = Convert.ToString(sdr["City"]);
BEtest.Phoneno = Convert.ToString(sdr["Phoneno"]);
BEtest.CId = Convert.ToInt32(sdr["CId"]);
list.Add(BEtest);
}
}
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
return list;
}
public void insert(BEtest be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spinsertinfo.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", be.Name);
cmd.Parameters.AddWithValue("@Address", be.Address);
cmd.Parameters.AddWithValue("@City", be.City);
cmd.Parameters.AddWithValue("@Phoneno", be.Phoneno);
cmd.Parameters.AddWithValue("@CId", be.CId);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
}
public void update(BEtest be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spupdateinfo.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
cmd.Parameters.AddWithValue("@Name", be.Name);
cmd.Parameters.AddWithValue("@Address", be.Address);
cmd.Parameters.AddWithValue("@City", be.City);
cmd.Parameters.AddWithValue("@Phoneno", be.Phoneno);
cmd.Parameters.AddWithValue("@CId", be.CId);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
}
public void delete(BEtest be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spdeleteinfo.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>MyconnectionString>>>>>>>>>>>>>>>>>>>>>>>>>.....
'using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
namespace DAl_test
{
public class MyConnectionString
{
public static string path;
static MyConnectionString()
{
path = ConfigurationManager.ConnectionStrings["Db"].ConnectionString;
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>My Proc?>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DAl_test
{
public class MyProc
{
public enum Name
{
show, spcount, spinsertinfo, spupdateinfo, spdeleteinfo
}
}
}
?>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>webconfig>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.......
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="Db" connectionString="Data Source=.;Initial Catalog=testtoday;Integrated Security=True" providerName="SystemSqlClient"/>
</connectionStrings>
</configuration>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Bl>>>>>>>>>>>>>>>>>>>>>>>.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE_test;
using DAl_test;
namespace Bl_test
{
public class BLCountry
{
public List<BECountry> show()
{
return new DALCountry().show();
}
}
}
------------------------2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE_test;
using DAl_test;
namespace Bl_test
{
public class Bltest
{
public List<BEtest> show()
{
return new DAltest().show();
}
public void insert(BEtest be)
{
new DAltest().insert(be);
}
public void update(BEtest be)
{
new DAltest().update(be);
}
public void delete(BEtest be)
{
new DAltest().delete(be);
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test.aspx>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="Webtest.test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
border-collapse: collapse;
border-color: #99FF66;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListVew1" runat="server" DataKeyNames="Id" OnItemEditing="ListView1_ItemEditing" OnItemUpdating="ListView1_ItemUpdating"
OnItemDeleting="ListView1_ItemDeleting" OnItemCanceling="ListView1_Cancelling">
<LayoutTemplate>
<table border="1">
<tr>
<td style="width: 100px">
Id
</td>
<td style="width: 100px">
Name
</td>
<td style="width: 100px">
Address
</td>
<td style="width: 200px">
City
</td>
<td style="width: 200px">
Phone
</td>
<td style="width: 200px">
Country
</td>
<td style="width: 200px">
Actions
</td>
</tr>
</table>
<div id="ItemPlaceholder" runat="server">
</div>
</table>
</LayoutTemplate>
<ItemTemplate>
<table border="1">
<tr>
<td style="width: 100px">
<%#Eval("Id")%>
</td>
<td style="width: 100px">
<%#Eval("Name") %>
</td>
<td style="width: 100px">
<%#Eval("Address") %>
</td>
<td style="width: 200px">
<%#Eval("City")%>
</td>
<td style="width: 200px">
<%#Eval("Phoneno")%>
</td>
<td style="width: 200px">
<%#Eval("Country")%>
</td>
<td style="width: 200px">
<asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="Delete" OnClientClick="return confirm('do you want to delete?')" />
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table border="1">
<tr>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Id") %>'></asp:TextBox>
</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox2" runat="server" Text='<%#Eval("Name") %>'></asp:TextBox>
</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox3" runat="server" Text='<%#Eval("Address") %>'></asp:TextBox>
</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox9" runat="server" Text='<%#Eval("City") %>'></asp:TextBox>
</td>
<td style="width: 200px">
<asp:TextBox ID="TextBox4" runat="server" Text='<%#Eval("Phoneno") %>'></asp:TextBox>
</td>
<td style="width: 200px">
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true">
</asp:DropDownList>
<asp:HiddenField ID="hfClientId" runat="server" Value='<%#Eval("CId")%>' />
</td>
<td style="width: 200px">
<asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:ListView>
<br />
<br />
<table class="style1">
<tr>
<td>
</td>
<td>
Name:</td>
<td>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
Address</td>
<td>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
City</td>
<td>
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
Phone Number</td>
<td>
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RF" runat="server" ErrorMessage="*" ControlToValidate="TextBox8"
ValidationGroup="Yes"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Only Alpha-Numeric"
Display="Dynamic" ControlToValidate="TextBox8" ValidationExpression="^[0-9\- \s]+$"
ValidationGroup="UP"> </asp:RegularExpressionValidator>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
Select Country</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="*" ControlToValidate="DropDownList1" ></asp:RequiredFieldValidator>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<asp:Button ID="btnSave" runat="server" EnableTheming="True" Text="Save"
onclick="btnSave_Click" />
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test.asps.cs>>>>>>>>>>>>>>>>>>>>>>>>>>......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bl_test;
using BE_test;
namespace Webtest
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dllupdate();
pp();
}
}
public void pp() {
List<BEtest> list = new Bltest().show();
foreach (BEtest item in list)
{
item.Country = new BLCountry().show().Single(id => id.CId == item.CId).Country;
}
ListVew1.DataSource = list;
ListVew1.DataBind();
}
public void dllupdate()
{
DropDownList1.DataSource = new BLCountry().show();
DropDownList1.DataTextField = "Country";
DropDownList1.DataValueField = "CId";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "----select----");
}
protected void btnSave_Click(object sender, EventArgs e)
{
BEtest be = new BEtest();
be.Name = TextBox5.Text;
be.Address = TextBox6.Text;
be.City = TextBox7.Text;
be.Phoneno = TextBox8.Text;
be.CId = Convert.ToInt32(DropDownList1.SelectedValue);
new Bltest().insert(be);
pp();
}
protected void ListView1_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListVew1.EditIndex = e.NewEditIndex;
pp();
ListViewDataItem item = ListVew1.Items[ListVew1.EditIndex] as ListViewDataItem;
DropDownList ddlClients = item.FindControl("DropDownList2") as DropDownList;
HiddenField hfClientId = item.FindControl("hfClientId") as HiddenField;
ddlClients.DataSource = new BLCountry().show();
ddlClients.DataTextField = "Country";
ddlClients.DataValueField = "CId";
ddlClients.DataBind();
ddlClients.SelectedValue = hfClientId.Value;
}
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
string lId = ListVew1.DataKeys[e.ItemIndex].Value.ToString();
TextBox detail2 = ListVew1.Items[e.ItemIndex].FindControl("TextBox2") as TextBox;
TextBox detail3 = ListVew1.Items[e.ItemIndex].FindControl("TextBox3") as TextBox;
TextBox detail4 = ListVew1.Items[e.ItemIndex].FindControl("TextBox4") as TextBox;
TextBox detail5 = ListVew1.Items[e.ItemIndex].FindControl("TextBox9") as TextBox;
BEtest bes = new BEtest();
bes.Id = Convert.ToInt32(lId);
bes.Name = detail2.Text;
bes.Address = detail3.Text;
bes.City = detail5.Text;
bes.Phoneno = detail4.Text;
bes.CId = Convert.ToInt32(((DropDownList)ListVew1.Items[e.ItemIndex].FindControl("DropDownList2")).SelectedValue);
new Bltest().update(bes);
ListVew1.EditIndex = -1;
pp();
}
protected void ListView1_ItemDeleting(object sender, ListViewDeleteEventArgs e)
{
string listId = ListVew1.DataKeys[e.ItemIndex].Value.ToString();
BEtest bem = new BEtest();
bem.Id = Convert.ToInt32(listId);
new Bltest().delete(bem);
pp();
}
protected void ListView1_Cancelling(object sender, ListViewCancelEventArgs e)
{
ListVew1.EditIndex = -1;
pp();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BE_test
{
public class BECountry
{
public int CId {get; set;}
public string Country { get; set; }
}
}
---------------------------------------2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BE_test
{
public class BEtest
{
public int Id {get; set;}
public string Name {get; set;}
public string Address {get; set;}
public string City {get; set;}
public string Phoneno {get; set;}
public int CId {get; set;}
public string Country { get; set; }
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>DAl>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE_test;
using System.Data.SqlClient;
using System.Data;
namespace DAl_test
{
public class DALCountry
{
private string connect = MyConnectionString.path;
public List<BECountry> show()
{
List<BECountry> list = new List<BECountry>();
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spcount.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
BECountry becountry = new BECountry();
becountry.CId = Convert.ToInt32(sdr["CId"]);
becountry.Country = Convert.ToString(sdr["Country"]);
list.Add(becountry);
}
}
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
return list;
}
}
}
------------------------------2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE_test;
using System.Data;
using System.Data.SqlClient;
namespace DAl_test
{
public class DAltest
{
private string connect = MyConnectionString.path;
public List<BEtest> show()
{
List<BEtest> list = new List<BEtest>();
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.show.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
BEtest BEtest = new BEtest();
BEtest.Id = Convert.ToInt32(sdr["Id"]);
BEtest.Name = Convert.ToString(sdr["Name"]);
BEtest.Address = Convert.ToString(sdr["Address"]);
BEtest.City = Convert.ToString(sdr["City"]);
BEtest.Phoneno = Convert.ToString(sdr["Phoneno"]);
BEtest.CId = Convert.ToInt32(sdr["CId"]);
list.Add(BEtest);
}
}
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
return list;
}
public void insert(BEtest be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spinsertinfo.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", be.Name);
cmd.Parameters.AddWithValue("@Address", be.Address);
cmd.Parameters.AddWithValue("@City", be.City);
cmd.Parameters.AddWithValue("@Phoneno", be.Phoneno);
cmd.Parameters.AddWithValue("@CId", be.CId);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
}
public void update(BEtest be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spupdateinfo.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
cmd.Parameters.AddWithValue("@Name", be.Name);
cmd.Parameters.AddWithValue("@Address", be.Address);
cmd.Parameters.AddWithValue("@City", be.City);
cmd.Parameters.AddWithValue("@Phoneno", be.Phoneno);
cmd.Parameters.AddWithValue("@CId", be.CId);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
}
public void delete(BEtest be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(MyProc.Name.spdeleteinfo.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception exe)
{
throw exe;
}
finally
{
con.Close();
}
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>MyconnectionString>>>>>>>>>>>>>>>>>>>>>>>>>.....
'using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
namespace DAl_test
{
public class MyConnectionString
{
public static string path;
static MyConnectionString()
{
path = ConfigurationManager.ConnectionStrings["Db"].ConnectionString;
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>My Proc?>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DAl_test
{
public class MyProc
{
public enum Name
{
show, spcount, spinsertinfo, spupdateinfo, spdeleteinfo
}
}
}
?>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>webconfig>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.......
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="Db" connectionString="Data Source=.;Initial Catalog=testtoday;Integrated Security=True" providerName="SystemSqlClient"/>
</connectionStrings>
</configuration>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Bl>>>>>>>>>>>>>>>>>>>>>>>.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE_test;
using DAl_test;
namespace Bl_test
{
public class BLCountry
{
public List<BECountry> show()
{
return new DALCountry().show();
}
}
}
------------------------2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE_test;
using DAl_test;
namespace Bl_test
{
public class Bltest
{
public List<BEtest> show()
{
return new DAltest().show();
}
public void insert(BEtest be)
{
new DAltest().insert(be);
}
public void update(BEtest be)
{
new DAltest().update(be);
}
public void delete(BEtest be)
{
new DAltest().delete(be);
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test.aspx>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="Webtest.test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
border-collapse: collapse;
border-color: #99FF66;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListVew1" runat="server" DataKeyNames="Id" OnItemEditing="ListView1_ItemEditing" OnItemUpdating="ListView1_ItemUpdating"
OnItemDeleting="ListView1_ItemDeleting" OnItemCanceling="ListView1_Cancelling">
<LayoutTemplate>
<table border="1">
<tr>
<td style="width: 100px">
Id
</td>
<td style="width: 100px">
Name
</td>
<td style="width: 100px">
Address
</td>
<td style="width: 200px">
City
</td>
<td style="width: 200px">
Phone
</td>
<td style="width: 200px">
Country
</td>
<td style="width: 200px">
Actions
</td>
</tr>
</table>
<div id="ItemPlaceholder" runat="server">
</div>
</table>
</LayoutTemplate>
<ItemTemplate>
<table border="1">
<tr>
<td style="width: 100px">
<%#Eval("Id")%>
</td>
<td style="width: 100px">
<%#Eval("Name") %>
</td>
<td style="width: 100px">
<%#Eval("Address") %>
</td>
<td style="width: 200px">
<%#Eval("City")%>
</td>
<td style="width: 200px">
<%#Eval("Phoneno")%>
</td>
<td style="width: 200px">
<%#Eval("Country")%>
</td>
<td style="width: 200px">
<asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="Delete" OnClientClick="return confirm('do you want to delete?')" />
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table border="1">
<tr>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Id") %>'></asp:TextBox>
</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox2" runat="server" Text='<%#Eval("Name") %>'></asp:TextBox>
</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox3" runat="server" Text='<%#Eval("Address") %>'></asp:TextBox>
</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox9" runat="server" Text='<%#Eval("City") %>'></asp:TextBox>
</td>
<td style="width: 200px">
<asp:TextBox ID="TextBox4" runat="server" Text='<%#Eval("Phoneno") %>'></asp:TextBox>
</td>
<td style="width: 200px">
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true">
</asp:DropDownList>
<asp:HiddenField ID="hfClientId" runat="server" Value='<%#Eval("CId")%>' />
</td>
<td style="width: 200px">
<asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:ListView>
<br />
<br />
<table class="style1">
<tr>
<td>
</td>
<td>
Name:</td>
<td>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
Address</td>
<td>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
City</td>
<td>
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
Phone Number</td>
<td>
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RF" runat="server" ErrorMessage="*" ControlToValidate="TextBox8"
ValidationGroup="Yes"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Only Alpha-Numeric"
Display="Dynamic" ControlToValidate="TextBox8" ValidationExpression="^[0-9\- \s]+$"
ValidationGroup="UP"> </asp:RegularExpressionValidator>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
Select Country</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="*" ControlToValidate="DropDownList1" ></asp:RequiredFieldValidator>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<asp:Button ID="btnSave" runat="server" EnableTheming="True" Text="Save"
onclick="btnSave_Click" />
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test.asps.cs>>>>>>>>>>>>>>>>>>>>>>>>>>......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bl_test;
using BE_test;
namespace Webtest
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dllupdate();
pp();
}
}
public void pp() {
List<BEtest> list = new Bltest().show();
foreach (BEtest item in list)
{
item.Country = new BLCountry().show().Single(id => id.CId == item.CId).Country;
}
ListVew1.DataSource = list;
ListVew1.DataBind();
}
public void dllupdate()
{
DropDownList1.DataSource = new BLCountry().show();
DropDownList1.DataTextField = "Country";
DropDownList1.DataValueField = "CId";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "----select----");
}
protected void btnSave_Click(object sender, EventArgs e)
{
BEtest be = new BEtest();
be.Name = TextBox5.Text;
be.Address = TextBox6.Text;
be.City = TextBox7.Text;
be.Phoneno = TextBox8.Text;
be.CId = Convert.ToInt32(DropDownList1.SelectedValue);
new Bltest().insert(be);
pp();
}
protected void ListView1_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListVew1.EditIndex = e.NewEditIndex;
pp();
ListViewDataItem item = ListVew1.Items[ListVew1.EditIndex] as ListViewDataItem;
DropDownList ddlClients = item.FindControl("DropDownList2") as DropDownList;
HiddenField hfClientId = item.FindControl("hfClientId") as HiddenField;
ddlClients.DataSource = new BLCountry().show();
ddlClients.DataTextField = "Country";
ddlClients.DataValueField = "CId";
ddlClients.DataBind();
ddlClients.SelectedValue = hfClientId.Value;
}
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
string lId = ListVew1.DataKeys[e.ItemIndex].Value.ToString();
TextBox detail2 = ListVew1.Items[e.ItemIndex].FindControl("TextBox2") as TextBox;
TextBox detail3 = ListVew1.Items[e.ItemIndex].FindControl("TextBox3") as TextBox;
TextBox detail4 = ListVew1.Items[e.ItemIndex].FindControl("TextBox4") as TextBox;
TextBox detail5 = ListVew1.Items[e.ItemIndex].FindControl("TextBox9") as TextBox;
BEtest bes = new BEtest();
bes.Id = Convert.ToInt32(lId);
bes.Name = detail2.Text;
bes.Address = detail3.Text;
bes.City = detail5.Text;
bes.Phoneno = detail4.Text;
bes.CId = Convert.ToInt32(((DropDownList)ListVew1.Items[e.ItemIndex].FindControl("DropDownList2")).SelectedValue);
new Bltest().update(bes);
ListVew1.EditIndex = -1;
pp();
}
protected void ListView1_ItemDeleting(object sender, ListViewDeleteEventArgs e)
{
string listId = ListVew1.DataKeys[e.ItemIndex].Value.ToString();
BEtest bem = new BEtest();
bem.Id = Convert.ToInt32(listId);
new Bltest().delete(bem);
pp();
}
protected void ListView1_Cancelling(object sender, ListViewCancelEventArgs e)
{
ListVew1.EditIndex = -1;
pp();
}
}
}
No comments :
Post a Comment