当前位置:编程学习 > C#/ASP.NET >>

asp.net中用c#实现添加版主?

一个网页想实现添加版主,原来的添加版主像注册用户一样重新注册了一个用户,只不过在添加过程中让选择了版块,版主和用户分为两个表,添加的版主信息在版主表里,现在不想这样添加,感觉不太方便,想直接拉两个dropdownlist一个用来选择用户一个用来选择版块,当点击添加按钮时的时候直接从用户表里把该用户直接调到版主表里,实现其版主添加。

原来的添加版主代码如下:
public partial class HostManage_ault : System.Web.UI.Page
{
HostManage hostmanage = new HostManage();
ModuleManage modulemanage = new ModuleManage();
ImageManage imagemanage = new ImageManage();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlModule.DataSource = modulemanage.GetAllModule("tb_Module").Tables[0].DefaultView;
ddlModule.DataTextField = "版块名称";
ddlModule.DataBind();
ddlPhoto.DataSource = imagemanage.GetAllPhoto("tb_Image").Tables[0].DefaultView;
ddlPhoto.DataTextField = "编号";
ddlPhoto.DataBind();
imagemanage.PhotoID = ddlPhoto.SelectedValue;
imgPhoto.ImageUrl = imagemanage.FindPhotoByID(imagemanage, "tb_Image").Tables[0].Rows[0][1].ToString();
}
}

追问:说的就是这个呀,因为字数限制没弄上去,

protected void btnAdd_Click(object sender, EventArgs e)
{
if (txtName.Text == string.Empty)
{
Response.Write("<script language=javascript>alert('版主名不能为空!')</script>");
}
else
{
hostmanage.HostName = txtName.Text;
DataSet ds = hostmanage.FindHostByName(hostmanage, "tb_Host");
if (ds.Tables[0].Rows.Count > 0)
{
Response.Write("<script language=javascript>alert('该版主已经存在!')</script>");
txtName.Text = string.Empty;
txtName.Focus();
}
else
{
try
{
modulemanage.ModuleName = ddlModule.SelectedValue;
hostmanage.ModuleID = modulemanage.FindModuleByName(modulemanage, "tb_Module").Tables[0].Rows[0][0].ToString();
}
catch
{
Response.Write("<script language=javascript>alert('请先填写版块信息!')</script>");
return;
}
hostmanage.HostPwd = txtPwd.Text;
hostmanage.TName = txtTName.Text;
if (ddlSex.SelectedIndex == 0)
hostmanage.Sex = true;
if (ddlSex.SelectedIndex == 1)
hostmanage.Sex = false;
hostmanage.Birthday = DateTime.Parse(txtBirthday.Text);
hostmanage.Tel = txtTel.Text;
hostmanage.Mobile = txtMobile.Text;
try
{
hostmanage.QQ = Int32.Parse(txtQQ.Text);
}
catch
{
txtQQ.Text = string.Empty;
Response.Write("<script language=javascript>alert('QQ号码输入错误!')</script>");
return;
}
imagemanage.PhotoID = ddlPhoto.SelectedValue;
hostmanage.Photo = imagemanage.FindPhotoByID(imagemanage, "tb_Image").Tables[0].Rows[0][1].ToString();
hostmanage.Email = txtEmail.Text;
hostmanage.FAddress = txtHAddress.Text;
hostmanage.RAddress = txtRAddress.Text;
hostmanage.Index = txtIndex.Text;
hostmanage.AddHost(hostmanage);
Response.Write("<script language=javascript>alert('版主添加成功!')</script>");
txtName.Text = txtPwd.Text = txtSPwd.Text = txtTName.Text = txtBirthday.Text = txtTel.Text
= txtMobile.Text = txtQQ.Text = txtEmail.Text = txtHAddress.Text = txtRAddress.Text = txtIndex.Text = string.Empty;
}
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
txtName.Text = txtPwd.Text = txtSPwd.Text = txtTName.Text = txtBirthday.Text = txtTel.Text
= txtMobile.Text = txtQQ.Text = txtEmail.Text = txtHAddress.Text = txtRAddress.Text = txtIndex.Text = string.Empty;
}
}

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,