根据上次的文章,我们使用相同的步骤进行开发模块。
此模块为一个dbgrid控件,使用它来读取数据库的内容。
将dbgrid System.Web.UI.WebControls.DataGrid 放到ascx(product.ascx) 页面中。
定义数据连接。
1 private void Connect()
2 {
3 if (objConnection==null)
4 {
5 objConnection=new SqlConnection(strConnection);
6 }
7 if (objConnection.State==ConnectionState.Closed)
8 {
9 objConnection.Open();
10 }
11 }
12 private void DisConnect()
13 {
14 objConnection.Close();
15 }
16 private void LoadGrid()
17 {
18 Connect();
19 string strSql="SELECT * from pdt_class";
20 //strSql=string.Format(strSql,this.GetSearchKey());
21 SqlDataAdapter adapter= new SqlDataAdapter(strSql,objConnection);
22
23 DataSet ds =new DataSet();
24 adapter.Fill(ds,"tblName");
25 DataView ordersView = new DataView(ds.Tables[0]);
26 DisConnect();
27 //dgSystemList.DataSource=ds.Tables[0];
28 dgSystemList.DataSource=ordersView;
29 dgSystemList.DataBind();
30 }
2 {
3 if (objConnection==null)
4 {
5 objConnection=new SqlConnection(strConnection);
6 }
7 if (objConnection.State==ConnectionState.Closed)
8 {
9 objConnection.Open();
10 }
11 }
12 private void DisConnect()
13 {
14 objConnection.Close();
15 }
16 private void LoadGrid()
17 {
18 Connect();
19 string strSql="SELECT * from pdt_class";
20 //strSql=string.Format(strSql,this.GetSearchKey());
21 SqlDataAdapter adapter= new SqlDataAdapter(strSql,objConnection);
22
23 DataSet ds =new DataSet();
24 adapter.Fill(ds,"tblName");
25 DataView ordersView = new DataView(ds.Tables[0]);
26 DisConnect();
27 //dgSystemList.DataSource=ds.Tables[0];
28 dgSystemList.DataSource=ordersView;
29 dgSystemList.DataBind();
30 }
可以定义一个按钮,挂载click实践进行loadgrid()便可以实现数据的显示了。
调试好后加上guid的值就可以放在rainbow中!
很简单吧。 下面将我写的程序代码全部贴出来。比较菜鸟的,大家应该都读的懂。
三个表
pdt_class--->产品的第一级目录。
pdt_type----〉第二级目录
pdt_infor----〉产品列表。
1namespace rainbowprj
2{
3 using System;
4 using System.Data;
5 using System.Drawing;
6 using System.Web;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.HtmlControls;
9 using System.Data.SqlClient;
10 using Rainbow.UI;
11 using Rainbow.UI.WebControls;
12
13 /// <summary>
14 /// classlist 的摘要说明。
15 /// </summary>
16 public class Product : PortalModuleControl
17 //public class Product : System.Web.UI.UserControl
18 {
19 protected System.Web.UI.WebControls.DataGrid dgSystemList;
20 const string strConnection = "server=TJPC014;database=pubs;uid=sa;pwd=sa;";
21 protected System.Web.UI.WebControls.Button Button1;
22 protected System.Web.UI.WebControls.DataGrid pdt_type;
23 protected System.Web.UI.WebControls.DataGrid pdt_infor;
24 protected System.Web.UI.WebControls.Label Label1;
25 protected System.Web.UI.WebControls.Label Label2;
26 protected System.Web.UI.WebControls.Button pdt_class_btn;
27 protected System.Web.UI.WebControls.Button pdt_type_btn;
28 private SqlConnection objConnection;
29 private void Page_Load(object sender, System.EventArgs e)
30 {
31 // 在此处放置用户代码以初始化页面
32 }
33
34 Web 窗体设计器生成的代码
61
62 public override Guid GuidID
63 {
64 get
65 {
66 return new Guid("{E2499B13-7E5D-4bc1-AB0D-7209792B64EB}");
67 }
68 }
69 private void Connect()
70 {
71 if (objConnection==null)
72 {
73 objConnection=new SqlConnection(strConnection);
74 }
75 if (objConnection.State==ConnectionState.Closed)
76 {
77 objConnection.Open();
78 }
79 }
80 private void DisConnect()
81 {
82 objConnection.Close();
83 }
84 private void LoadGrid()
85 {
86 Connect();
87 string strSql="SELECT * from pdt_class";
88 //strSql=string.Format(strSql,this.GetSearchKey());
89 SqlDataAdapter adapter= new SqlDataAdapter(strSql,objConnection);
90
91 DataSet ds =new DataSet();
92 adapter.Fill(ds,"tblName");
93 DataView ordersView = new DataView(ds.Tables[0]);
94 DisConnect();
95 //dgSystemList.DataSource=ds.Tables[0];
96 dgSystemList.DataSource=ordersView;
97 dgSystemList.DataBind();
98 }
99
100 private void LoadGrid_type(string str_type)
101 {
102 Connect();
103 string strSql="SELECT * from pdt_type where classname='"+str_type.ToString()+"'";
104 //strSql=string.Format(strSql,this.GetSearchKey());
105 SqlDataAdapter adapter= new SqlDataAdapter(strSql,objConnection);
106
107 DataSet ds =new DataSet();
108 adapter.Fill(ds,"tblName");
109 DataView ordersView = new DataView(ds.Tables[0]);
110 DisConnect();
111 //dgSystemList.DataSource=ds.Tables[0];
112 pdt_type.DataSource=ordersView;
113 pdt_type.DataBind();
114 this.pdt_class_btn.Visible=true;
115 }
116
117 private void LoadGrid_pdt(string str_class,string str_type)
118 {
119 Connect();
120 string strSql="SELECT * from pdt_infor where classname='"+str_class.ToString()+"' and typename='"+str_type.ToString()+"'";
121 //strSql=string.Format(strSql,this.GetSearchKey());
122 SqlDataAdapter adapter= new SqlDataAdapter(strSql,objConnection);
123
124 DataSet ds =new DataSet();
125 adapter.Fill(ds,"tblName");
126 DataView ordersView = new DataView(ds.Tables[0]);
127 DisConnect();
128 //dgSystemList.DataSource=ds.Tables[0];
129 pdt_infor.DataSource=ordersView;
130 pdt_infor.DataBind();
131 this.pdt_class_btn.Visible=true;
132 }
133
134 private void pdt_class_btn_Click(object sender, System.EventArgs e)
135 {
136 LoadGrid();
137 this.pdt_class_btn.Visible=false;
138 this.pdt_type_btn.Visible=false;
139 this.dgSystemList.Visible=true;
140 this.pdt_type.Visible=false;
141 this.pdt_infor.Visible=false;
142 }
143
144 private void dgSystemList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
145 {
146 dgSystemList.CurrentPageIndex = e.NewPageIndex;
147
148 dgSystemList.DataBind();
149 LoadGrid();
150 }
151
152 private void dgSystemList_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
153 {
154 this.LoadGrid_type(e.Item.Cells[0].Text.ToString());
155 this.dgSystemList.Visible=false;
156 this.pdt_type.Visible=true;
157 }
158
159 private void pdt_type_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
160 {
161 this.LoadGrid_pdt(e.Item.Cells[1].Text.ToString(),e.Item.Cells[2].Text.ToString());
162 this.dgSystemList.Visible=false;
163 this.pdt_type.Visible=false;
164 this.pdt_infor.Visible=true;
165 this.pdt_type_btn.Visible=true;
166 this.pdt_class_btn.Visible=true;
167 this.Label1.Text=e.Item.Cells[1].Text.ToString();
168 this.Label2.Text=e.Item.Cells[2].Text.ToString();
169 }
170
171 private void pdt_type_btn_Click(object sender, System.EventArgs e)
172 {
173 this.LoadGrid_type(this.Label1.Text.ToString());
174 this.pdt_class_btn.Visible=true;
175 this.pdt_type_btn.Visible=false;
176 this.dgSystemList.Visible=false;
177 this.pdt_type.Visible=true;
178 this.pdt_infor.Visible=false;
179 }
180 }
181}
182
2{
3 using System;
4 using System.Data;
5 using System.Drawing;
6 using System.Web;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.HtmlControls;
9 using System.Data.SqlClient;
10 using Rainbow.UI;
11 using Rainbow.UI.WebControls;
12
13 /// <summary>
14 /// classlist 的摘要说明。
15 /// </summary>
16 public class Product : PortalModuleControl
17 //public class Product : System.Web.UI.UserControl
18 {
19 protected System.Web.UI.WebControls.DataGrid dgSystemList;
20 const string strConnection = "server=TJPC014;database=pubs;uid=sa;pwd=sa;";
21 protected System.Web.UI.WebControls.Button Button1;
22 protected System.Web.UI.WebControls.DataGrid pdt_type;
23 protected System.Web.UI.WebControls.DataGrid pdt_infor;
24 protected System.Web.UI.WebControls.Label Label1;
25 protected System.Web.UI.WebControls.Label Label2;
26 protected System.Web.UI.WebControls.Button pdt_class_btn;
27 protected System.Web.UI.WebControls.Button pdt_type_btn;
28 private SqlConnection objConnection;
29 private void Page_Load(object sender, System.EventArgs e)
30 {
31 // 在此处放置用户代码以初始化页面
32 }
33
34 Web 窗体设计器生成的代码
61
62 public override Guid GuidID
63 {
64 get
65 {
66 return new Guid("{E2499B13-7E5D-4bc1-AB0D-7209792B64EB}");
67 }
68 }
69 private void Connect()
70 {
71 if (objConnection==null)
72 {
73 objConnection=new SqlConnection(strConnection);
74 }
75 if (objConnection.State==ConnectionState.Closed)
76 {
77 objConnection.Open();
78 }
79 }
80 private void DisConnect()
81 {
82 objConnection.Close();
83 }
84 private void LoadGrid()
85 {
86 Connect();
87 string strSql="SELECT * from pdt_class";
88 //strSql=string.Format(strSql,this.GetSearchKey());
89 SqlDataAdapter adapter= new SqlDataAdapter(strSql,objConnection);
90
91 DataSet ds =new DataSet();
92 adapter.Fill(ds,"tblName");
93 DataView ordersView = new DataView(ds.Tables[0]);
94 DisConnect();
95 //dgSystemList.DataSource=ds.Tables[0];
96 dgSystemList.DataSource=ordersView;
97 dgSystemList.DataBind();
98 }
99
100 private void LoadGrid_type(string str_type)
101 {
102 Connect();
103 string strSql="SELECT * from pdt_type where classname='"+str_type.ToString()+"'";
104 //strSql=string.Format(strSql,this.GetSearchKey());
105 SqlDataAdapter adapter= new SqlDataAdapter(strSql,objConnection);
106
107 DataSet ds =new DataSet();
108 adapter.Fill(ds,"tblName");
109 DataView ordersView = new DataView(ds.Tables[0]);
110 DisConnect();
111 //dgSystemList.DataSource=ds.Tables[0];
112 pdt_type.DataSource=ordersView;
113 pdt_type.DataBind();
114 this.pdt_class_btn.Visible=true;
115 }
116
117 private void LoadGrid_pdt(string str_class,string str_type)
118 {
119 Connect();
120 string strSql="SELECT * from pdt_infor where classname='"+str_class.ToString()+"' and typename='"+str_type.ToString()+"'";
121 //strSql=string.Format(strSql,this.GetSearchKey());
122 SqlDataAdapter adapter= new SqlDataAdapter(strSql,objConnection);
123
124 DataSet ds =new DataSet();
125 adapter.Fill(ds,"tblName");
126 DataView ordersView = new DataView(ds.Tables[0]);
127 DisConnect();
128 //dgSystemList.DataSource=ds.Tables[0];
129 pdt_infor.DataSource=ordersView;
130 pdt_infor.DataBind();
131 this.pdt_class_btn.Visible=true;
132 }
133
134 private void pdt_class_btn_Click(object sender, System.EventArgs e)
135 {
136 LoadGrid();
137 this.pdt_class_btn.Visible=false;
138 this.pdt_type_btn.Visible=false;
139 this.dgSystemList.Visible=true;
140 this.pdt_type.Visible=false;
141 this.pdt_infor.Visible=false;
142 }
143
144 private void dgSystemList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
145 {
146 dgSystemList.CurrentPageIndex = e.NewPageIndex;
147
148 dgSystemList.DataBind();
149 LoadGrid();
150 }
151
152 private void dgSystemList_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
153 {
154 this.LoadGrid_type(e.Item.Cells[0].Text.ToString());
155 this.dgSystemList.Visible=false;
156 this.pdt_type.Visible=true;
157 }
158
159 private void pdt_type_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
160 {
161 this.LoadGrid_pdt(e.Item.Cells[1].Text.ToString(),e.Item.Cells[2].Text.ToString());
162 this.dgSystemList.Visible=false;
163 this.pdt_type.Visible=false;
164 this.pdt_infor.Visible=true;
165 this.pdt_type_btn.Visible=true;
166 this.pdt_class_btn.Visible=true;
167 this.Label1.Text=e.Item.Cells[1].Text.ToString();
168 this.Label2.Text=e.Item.Cells[2].Text.ToString();
169 }
170
171 private void pdt_type_btn_Click(object sender, System.EventArgs e)
172 {
173 this.LoadGrid_type(this.Label1.Text.ToString());
174 this.pdt_class_btn.Visible=true;
175 this.pdt_type_btn.Visible=false;
176 this.dgSystemList.Visible=false;
177 this.pdt_type.Visible=true;
178 this.pdt_infor.Visible=false;
179 }
180 }
181}
182