📄 studentwebpatr.cs
字号:
namespace Stu.Student
{
using System;
using System.Web;
using System.Web.Security;
using System.Security.Permissions;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class StudentWebPatr : WebPart, INamingContainer
{
// 定义构造函数
public StudentWebPatr()
{
this.Title = "通信订阅者";
}
// 定义私有变量
private int _stuID;
private GridView gvinfo;
private SqlDataSource stuSql;
protected override void RenderContents(HtmlTextWriter writer)
{
if (_stuID < 1)
{
writer.Write("<span style='color:gray'>请在文本框中输入大于等于1的值.</span>");
return;
}
else
{
stuSql = new SqlDataSource();
stuSql.ID = "sqlDatasource1";
stuSql.ConnectionString = "Data Source=a\\mr;Initial Catalog=aspnetdb;Integrated Security=True";
stuSql.SelectCommand = "select * from tb_03 where 学生编号=" + _stuID.ToString();
Controls.Add(stuSql);
gvinfo = new GridView();
gvinfo.DataSourceID = "sqlDatasource1";
gvinfo.CellPadding = 3;
gvinfo.GridLines = GridLines.None;
Controls.Add(gvinfo);
gvinfo.RenderControl(writer);
}
}
// 实现从IStuInfo接口定义的属性中获取数据
[ConnectionConsumer("IStuInfoConsumer", "IStuInfoConsumer")]
public void GetEmployeeInfo(IStuInfo StuInfo)
{
if (StuInfo != null)
{
_stuID = StuInfo.stuId;
}
else
{
throw new NotSupportedException("未能连接Sql数据库.");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -