⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttsv.aspx

📁 web asp.net, code c# and use xml.
💻 ASPX
字号:
<%@ Page Language="C#" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.OleDb" %>
<%@Import Namespace="System.Xml" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != null)
        {
            lbkq.Text ="Chào "+ Session["username"].ToString();
            string strCurrentPath = Request.PhysicalPath;
            string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\"))
                                + "\\QuanlySinhVien.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(strXMLPath);
            XmlNodeList mssv, tho, lop,diem,monhoc;
            mssv = doc.DocumentElement.SelectNodes("//SVien/MSSV");
            tho = doc.DocumentElement.SelectNodes("//SVien/HoTen");
            lop = doc.DocumentElement.SelectNodes("//Lop/Ten");
            diem = doc.DocumentElement.SelectNodes("//Diem/DiemThi");
            monhoc = doc.DocumentElement.SelectNodes("//Diem/MonHocID");
            DataTable s = new DataTable("table");                       
            s.Columns.Add("MSSV", Type.GetType("System.String"));
            s.Columns.Add("Họ Tên sv", Type.GetType("System.String"));
            s.Columns.Add("Lớp", Type.GetType("System.String"));
            s.Columns.Add("Điểm", Type.GetType("System.String")); 
            s.Columns.Add("Môn", Type.GetType("System.String"));
            for (int i = 0; i < tho.Count; i++)
            {

                    DataRow r = s.NewRow();
                    r["MSSV"] = mssv[i].FirstChild.Value;
                    r["Họ Tên sv"] = tho[i].FirstChild.Value;
                    r["Lớp"] = lop[0].FirstChild.Value;
                    r["Điểm"] = diem[i].FirstChild.Value;
                    r["Môn"] = monhoc[i].FirstChild.Value;
                    s.Rows.Add(r);             
            }
            s.ReadXml(strXMLPath);          
            gr.DataSource = s;
            gr.DataBind();
        }
        else
        {
            Response.Redirect("Login.aspx");
        }
    }

    protected void bttim_Click(object sender, EventArgs e)
    {
        string ttim = txtttimkiem.Value;
        string strCurrentPath = Request.PhysicalPath;
        string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\"))
                            + "\\QuanlySinhVien.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(strXMLPath);
        XmlNodeList mssv, tho, lop, diem, monhoc;
        mssv = doc.DocumentElement.SelectNodes("//SVien/MSSV");
        tho = doc.DocumentElement.SelectNodes("//SVien/HoTen");
        lop = doc.DocumentElement.SelectNodes("//Lop/Ten");
        diem = doc.DocumentElement.SelectNodes("//Diem/DiemThi");
        monhoc = doc.DocumentElement.SelectNodes("//Diem/MonHocID");
        DataTable s = new DataTable("table");
        s.Columns.Add("MSSV", Type.GetType("System.String"));
        s.Columns.Add("Họ Tên sv", Type.GetType("System.String"));
        s.Columns.Add("Lớp", Type.GetType("System.String"));
        s.Columns.Add("Điểm", Type.GetType("System.String"));
        s.Columns.Add("Môn", Type.GetType("System.String"));
        for (int i = 0; i < tho.Count; i++)
        {
            if (ttim == mssv[i].FirstChild.Value)
            {
                DataRow r = s.NewRow();
                r["MSSV"] = mssv[i].FirstChild.Value;
                r["Họ Tên sv"] = tho[i].FirstChild.Value;
                r["Lớp"] = lop[0].FirstChild.Value;
                r["Điểm"] = diem[i].FirstChild.Value;
                r["Môn"] = monhoc[i].FirstChild.Value;
                s.Rows.Add(r);
            }
        }
        s.ReadXml(strXMLPath);
        gr.DataSource = s;
        gr.DataBind();
    }

    protected void bttrove_Click(object sender, EventArgs e)
    {
        Response.Redirect("Login.aspx");
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lbkq" runat="server" Height="25px" Style="z-index: 100; left: 21px;
            position: absolute; top: 11px"></asp:Label>
        &nbsp;&nbsp;&nbsp; &nbsp;
        <br />
        <asp:Label ID="T" runat="server" Style="left: 0px; position: relative; top: 16px; z-index: 102;"
            Text="Tìm kiếm"></asp:Label><asp:Button ID="bttim" runat="server" OnClick="bttim_Click"
                Style="left: 192px; position: relative; top: 16px; z-index: 103;" Text="Tìm" /><input id="txtttimkiem"
                    runat="server" style="left: -6px; position: relative; top: 16px; z-index: 107;" type="text" /><asp:Button
                        ID="bttrove" runat="server" OnClick="bttrove_Click" Style="left: 56px; position: relative;
                        top: 16px; z-index: 104;" Text="Trở về" /></div>
        <asp:GridView ID="gr" runat="server" Height="1px" Style="z-index: 106; left: 19px;
            position: absolute; top: 108px" Width="395px" >
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    </form>
</body>
</html>
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -