protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int id = 0, cid = 0;
try
{
id = int.Parse(Request["id"]);//用来判断它是添加还是修改
ViewState.Add("id", id);
cid = int.Parse(Request["cid"]);//上个list文件传过来的categoryID,用来确定添加的文件属于哪个类别
ViewState.Add("cid", cid);
}
catch
{
this.GoError("页面错误", "无效的参数或链接错误。");
}
if (id > 0) //修改
{
DetailsViewFile.DataSource = MediaFile.GetListByCategoryID(id);
DetailsViewFile.DataBind();
MediaFile file = new MediaFile(id);
MediaCategories category = new MediaCategories(file.CategoryID);
DropDownList ddl = (DropDownList)DetailsViewFile.Rows[0].FindControl("dropCategory");
ddl.DataSource = MediaCategories.GetInfoByCategoryID(category.ParentID);
ddl.DataBind();
ddl.SelectedValue = file.CategoryID.ToString();
ViewState.Add("cid",cid);
}
else //添加
{
MediaCategories category = new MediaCategories(cid);
DetailsViewFile.DefaultMode = DetailsViewMode.Insert;
DropDownList ddl = (DropDownList)DetailsViewFile.Rows[0].FindControl("dropCategory");
if (category.Level == 1)
{
ddl.DataSource = MediaCategories.GetInfoByCategoryID(cid);
ddl.DataBind();
}
else
{
ddl.DataSource = MediaCategories.GetInfoByCategoryID(category.ParentID);
ddl.DataBind();
ddl.SelectedValue = category.CategoryID.ToString();
}
}
}
}
就这段代码,修改和添加是一个页面,所以进行了判断,页面加载时的时候,请您帮看看吧!先谢了!