using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class addSer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["userId"] == null)
{
Response.Write("<script>alert('你还没有登陆');window.target='main';window.location.href='logic.aspx'</script>");
}
else
{
// DetailsView1.DefaultMode = DetailsViewMode.Insert;
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dr = (DropDownList)FormView1.FindControl("DropDownList1");
SqlDataSource1.InsertParameters[1].DefaultValue = dr.SelectedValue;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dr = (DropDownList)FormView1.FindControl("DropDownList2");
SqlDataSource1.InsertParameters[7].DefaultValue = dr.SelectedValue;
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dr = (DropDownList)FormView1.FindControl("DropDownList3");
SqlDataSource1.InsertParameters[8].DefaultValue = dr.SelectedValue;
}
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dr = (DropDownList)FormView1.FindControl("DropDownList4");
SqlDataSource1.InsertParameters[10].DefaultValue = dr.SelectedValue;
}
protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
{
if (SqlDataSource1.InsertParameters[1].DefaultValue == null)
{
DropDownList dr = (DropDownList)FormView1.FindControl("DropDownList1");
SqlDataSource1.InsertParameters[1].DefaultValue = dr.Text;
}
if (SqlDataSource1.InsertParameters[7].DefaultValue == null)
{
DropDownList dr = (DropDownList)FormView1.FindControl("DropDownList2");
SqlDataSource1.InsertParameters[7].DefaultValue = dr.Text;
}
if (SqlDataSource1.InsertParameters[8].DefaultValue == null)
{
DropDownList dr = (DropDownList)FormView1.FindControl("DropDownList3");
SqlDataSource1.InsertParameters[8].DefaultValue = dr.Text;
}
if (SqlDataSource1.InsertParameters[10].DefaultValue == null)
{
DropDownList dr = (DropDownList)FormView1.FindControl("DropDownList4");
SqlDataSource1.InsertParameters[10].DefaultValue = dr.Text;
}
}
protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
Response.Write("<script>alert('插入成功,请继续添加');</script>");
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="addSer.aspx.cs" Inherits="addSer" %>
<!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>
</head>
<body>
<form ></asp:SqlDataSource>
<br />
</form>
</body>
</html>