ASPNET服务端控件练习(一个机试题)

2020-11-15 08:23

阅读:711

标签:des   com   http   class   blog   style   div   img   code   java   javascript   

简单记录:

模糊查询的select语句的拼写

soscw.com,搜素材
        public List GetWhereStudent(string name, string sub, string isG)
        {
            List lt = new List();
            string sql = "select * from SC_Student where studentName like @n and Subjects=@sub and IsGoodStudent=@is";
            SqlParameter[] param = { 
             new SqlParameter("@n","%"+name+"%"),
             new SqlParameter("@sub",sub),
             new SqlParameter("@is",isG)};
            using (SqlDataReader reader = SqlHelper.ExecuteDataReader(sql, param))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Web.Model.Student stu = new Model.Student();
                        stu.ID = reader.GetInt32(0);
                        stu.Name = reader.GetString(1);
                        stu.SubId = this.GetSubName(reader.GetInt32(2));
                        stu.Score = reader.GetInt32(3);
                        stu.IsGoodStudent = reader.GetBoolean(4);
                        lt.Add(stu);
                    }
                }
            }
            return lt;
        }
soscw.com,搜素材

reader拿取 ROW_NUMBER() over(order by studentName)产生的值

soscw.com,搜素材
        public List EditStudent(string name, string sco)
        {
            List lst = new List();
            int s = 0;
            SqlParameter[] param = 
            { 
                         new SqlParameter("@likes","%"+name+"%"),
                         new SqlParameter("@sco",int.TryParse(sco,out s)==true?s:0)
                                   };
            using (SqlDataReader reader = SqlHelper.ExecuteProcedure("pro_Student_Avg", param))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Web.Model.StudentAvg stuavg = new Model.StudentAvg();
                        //拿取 ROW_NUMBER() over(order by studentName)产生的值
                        stuavg.ID = int.Parse(reader.GetSqlValue(0).ToString());
                        stuavg.Name = reader.GetString(1);
                        stuavg.SSum = reader.GetInt32(2);
                        stuavg.SAvg = reader.GetInt32(3);
                        lst.Add(stuavg);
                    }
                }
            }
            return lst;
        }
soscw.com,搜素材

对于动态的对ObjectDataSource控件添加参数之前先清空参数:不然参数数据源的SelectParameters会叠加递增的

soscw.com,搜素材
    protected void Page_Load(object sender, EventArgs e)
    {
        this.ObjectDataSource1.SelectParameters.Clear();
        this.ObjectDataSource1.SelectParameters.Add("name", "");
        this.ObjectDataSource1.SelectParameters.Add("sco", "0");
        this.ObjectDataSource1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.ObjectDataSource1.SelectParameters.Clear();
        string name = this.txtName.Text;
        string sco = this.txtSco.Text;
        this.ObjectDataSource1.SelectParameters.Add("name", name);
        this.ObjectDataSource1.SelectParameters.Add("sco", sco);
        //Web.BLL.Tran tran = new Web.BLL.Tran();
        //List lst = tran.GetStudentAvg(name, sco);
        this.ObjectDataSource1.DataBind();
    }
soscw.com,搜素材

Repeater应用实例:里面的table tr项模版不能是服务端的

soscw.com,搜素材
    
"form1" runat="server">
"lst"> 学号 姓名 科目 分数 好学生 操作 > "false" OnClientClick="Del()" ID="isG" runat="server">设置为好学生--%> "ObjectDataSource1" runat="server" SelectMethod="GetAllStudent" TypeName="Web.BLL.Tran"> "lst"> "Repeater1" runat="server" DataSourceID="ObjectDataSource1">

// Parameters:
// expression:
// The navigation path from the container to the public property value to place
// in the bound control property.

                            
学号 姓名 科目 分数 好学生 操作
"ID") %> "Name") %> "SubId")).StuId %> "Score") %> "LinkButton1" Enabled= CommandArgument= OnClick="Unnamed_Click" runat="server"> bool)Eval("IsGoodStudent") ==true ? "好学生" : "设置为好学生" %> Edit_Student.aspx?id=>编辑  javascript:Del();>删除



"Panel1" runat="server" GroupingText="学生查询"> "ObjectDataSource2" runat="server" SelectMethod="GetAllSubject" TypeName="Web.BLL.Tran"> 姓名:"txtSName" runat="server">
科目:"DropDownList1" runat="server" DataSourceID="ObjectDataSource2" DataTextField="StuId" DataValueField="Id">
是否是好学生:"CheckBox1" runat="server" />
soscw.com,搜素材
soscw.com,搜素材
    protected void Unnamed_Click(object sender, EventArgs e)
    {
        //还原 参数
        this.ObjectDataSource1.SelectParameters.Clear();
        LinkButton lb = ((LinkButton)sender);
        if (lb.CommandArgument != "")
        {
            if (true)//YEs No 对话框
            {
                string id = lb.CommandArgument;

                Web.BLL.Tran tran = new Web.BLL.Tran();
                if (tran.SetGood(int.Parse(id)) == 1)
                {
                    this.Repeater1.DataBind();
                }
            }

        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.ObjectDataSource1.SelectParameters.Clear();
        this.ObjectDataSource1.SelectParameters.Add("name", this.txtSName.Text);
        this.ObjectDataSource1.SelectParameters.Add("sub", this.DropDownList1.SelectedIndex + 1.ToString());
        this.ObjectDataSource1.SelectParameters.Add("isG", this.CheckBox1.Checked == true ? "1" : "0");
        this.ObjectDataSource1.SelectMethod = "GetWhereStudent";
        this.ObjectDataSource1.DataBind();
        //this.Page.DataBind();
        //this.ObjectDataSource1.SelectMethod = "GetWhereStudent";
    }
soscw.com,搜素材

js界面删除表格行

soscw.com,搜素材
        function DelRow() {
            var ta = document.getElementById("lst");
            var len=ta.rows.length;
            for (var i = 1; i ) {
                var ro = ta.rows.item(i);
                if (ro.childNodes[0].innerHTML = arguments[0]) {
                    ta.deleteRow(i);
                    return;
                }
            }
        };
soscw.com,搜素材

ListView下拿后台拿服务端控件值

soscw.com,搜素材
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = Request.QueryString["id"];
            if (id != null)
            {
                //this.ObjectDataSource1.SelectParameters.Add("id", id);
                this.ObjectDataSource1.SelectParameters[0].DefaultValue = id;
                this.ObjectDataSource1.DataBind();
            }
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Web.BLL.Tran tran = new Web.BLL.Tran();
        string id = ((TextBox)this.ListView1.Items[0].Controls[1]).Text;
        string name = ((TextBox)this.ListView1.Items[0].Controls[3]).Text;
        string sub = ((TextBox)this.ListView1.Items[0].Controls[5]).Attributes["MySubID"];
        string sco = ((TextBox)this.ListView1.Items[0].Controls[7]).Text;
        bool isG = ((CheckBox)this.ListView1.Items[0].Controls[9]).Checked;
        if (1 == tran.EditStudent(id, name, sub, sco, isG))
        {
            this.ObjectDataSource1.DataBind();
            Response.Redirect("Manage_Student.aspx");
        }
    }
soscw.com,搜素材
soscw.com,搜素材
    
"form1" runat="server">
"ObjectDataSource1" runat="server" SelectMethod="GetStudent" TypeName="Web.BLL.Tran"> "id" Type="Int32" />
"ListView1" runat="server" DataSourceID="ObjectDataSource1">
学号 姓名 科目 分数 好学生
"TextBox4" disabled="disabled" runat="server" Text=> "TextBox1" runat="server" Text=> "TextBox3" disabled="disabled" MySubID= Text= runat="server"> "TextBox2" runat="server" Text=> "CheckBox1" runat="server" Checked= />
soscw.com,搜素材

服务端控件DropDownList绑定数据

soscw.com,搜素材
            

"text" name="txtName" />
                
                    "server" ID="scoName" DataSourceID="ObjectDataSource1" DataTextField="StuId" DataValueField="Id">
                    

                
"text" name="txtSco" />
                
                    "" runat="server" ID="IsGoodStudent" />

            
soscw.com,搜素材

后台获取服务端控件CheckBox的选择值

soscw.com,搜素材
        bool isGS = this.IsGoodStudent.Checked;
soscw.com,搜素材

项目文件:http://pan.baidu.com/s/1gdJxjvt

ASPNET服务端控件练习(一个机试题),搜素材,soscw.com

ASPNET服务端控件练习(一个机试题)

标签:des   com   http   class   blog   style   div   img   code   java   javascript   

原文地址:http://www.cnblogs.com/wjshan0808/p/3698169.html


评论


亲,登录后才可以留言!