我正在开发Web用户控件。我创建了两个简单的Web用户控件。第一个是将数据保存在数据库中,第二个是检索数据。他们工作得很好。如何在asp.net中的一个页面上使用两个Web用户控件
但现在我试图将这两个控件添加到单个页面上,用户可以输入他的数据,并在没有页面加载的情况下更新数据库中的最新数据。
这是在web用户控件
protected void BtnSave_Click(object sender, EventArgs e)
{
UserBO userBO = new UserBO();
userBO.Name = txtname.Text;
userBO.address = txAddress.Text;
userBO.EmailID = txtEmailid.Text;
userBO.Mobilenumber = txtmobile.Text;
UserBL userBL = new UserBL();
userBL.SaveUserregisrationBL(userBO);
txtEmailid.Text = null;
txAddress.Text = null;
txtmobile.Text = null;
txtname.Text = null;
}
使用存储过程进行插入数据的代码,这是从数据库的Web用户控件获得用户的详细信息代码
protected void Page_Load(object sender, EventArgs e)
{
Bussinesslogic.UserBL bl = new Bussinesslogic.UserBL();
GridView1.DataSource = bl.getUserDetails();
GridView1.DataBind();
}
这是我的逻辑
public class UserBL
{
public int SaveUserregisrationBL(UserBO objUserBL) // passing Business object here
{
try
{
UserDA objUserda = new UserDA(); // Creating object of Dataccess
return objUserda.AddUserDetails(objUserBL); // calling Method of DataAccess
}
catch
{
throw;
}
}
public DataSet getUserDetails() // passing Business object Here
{
try
{
UserDA da = new UserDA();
return da.getUserDetail();
}
catch
{
throw;
}
}
}
和我的数据访问层是
public class UserDA
{
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString());
public int AddUserDetails(UserBO ObjBO) // passing Business object here
{
try
{
/* Because we will put all out values from our (UserRegistration.aspx)
To in Business object and then Pass it to Business logic and then to
DataAcess
this way the flow carry on*/
SqlCommand cmd = new SqlCommand("sprocUserinfoInsertUpdateSingleItem", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", ObjBO.Name);
cmd.Parameters.AddWithValue("@Address", ObjBO.address);
cmd.Parameters.AddWithValue("@EmailID", ObjBO.EmailID);
cmd.Parameters.AddWithValue("@Mobilenumber", ObjBO.Mobilenumber);
con.Open();
int Result = cmd.ExecuteNonQuery();
cmd.Dispose();
return Result;
}
catch
{
throw;
}
}
public DataSet getUserDetail()
{
string query = "SPGetUserInfo";
SqlDataAdapter adp = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
adp.Fill(ds);
return ds;
}
}