继上次写的《首次的Rainbow 模块Hello World 》,继续纪录我的开发经历。
根据上次的文章,我们使用相同的步骤进行开发模块。
此模块为一个dbgrid控件,使用它来读取数据库的内容。
将dbgrid System.Web.UI.WebControls.DataGrid 放到ascx(product.ascx) 页面中。
定义数据连接。
根据上次的文章,我们使用相同的步骤进行开发模块。
此模块为一个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
}
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
11
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
可以定义一个按钮,挂载click实践进行loadgrid()便可以实现数据的显示了。
调试好后加上guid的值就可以放在rainbow中!
很简单吧。 下面将我写的程序代码全部贴出来。比较菜鸟的,大家应该都读的懂。
三个表
pdt_class--->产品的第一级目录。
pdt_type----〉第二级目录
pdt_infor----〉产品列表。
1
namespace 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![](/Images/OutliningIndicators/InBlock.gif)
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![](/Images/OutliningIndicators/InBlock.gif)
34
Web 窗体设计器生成的代码
61![](/Images/OutliningIndicators/InBlock.gif)
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![](/Images/OutliningIndicators/InBlock.gif)
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![](/Images/OutliningIndicators/InBlock.gif)
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![](/Images/OutliningIndicators/InBlock.gif)
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![](/Images/OutliningIndicators/InBlock.gif)
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![](/Images/OutliningIndicators/InBlock.gif)
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![](/Images/OutliningIndicators/InBlock.gif)
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![](/Images/OutliningIndicators/InBlock.gif)
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![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
33
![](/Images/OutliningIndicators/InBlock.gif)
34
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
61
![](/Images/OutliningIndicators/InBlock.gif)
62
![](/Images/OutliningIndicators/InBlock.gif)
63
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
64
![](/Images/OutliningIndicators/InBlock.gif)
65
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
66
![](/Images/OutliningIndicators/InBlock.gif)
67
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
68
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
69
![](/Images/OutliningIndicators/InBlock.gif)
70
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
71
![](/Images/OutliningIndicators/InBlock.gif)
72
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
73
![](/Images/OutliningIndicators/InBlock.gif)
74
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
75
![](/Images/OutliningIndicators/InBlock.gif)
76
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
77
![](/Images/OutliningIndicators/InBlock.gif)
78
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
79
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
80
![](/Images/OutliningIndicators/InBlock.gif)
81
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
82
![](/Images/OutliningIndicators/InBlock.gif)
83
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
84
![](/Images/OutliningIndicators/InBlock.gif)
85
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
86
![](/Images/OutliningIndicators/InBlock.gif)
87
![](/Images/OutliningIndicators/InBlock.gif)
88
![](/Images/OutliningIndicators/InBlock.gif)
89
![](/Images/OutliningIndicators/InBlock.gif)
90
![](/Images/OutliningIndicators/InBlock.gif)
91
![](/Images/OutliningIndicators/InBlock.gif)
92
![](/Images/OutliningIndicators/InBlock.gif)
93
![](/Images/OutliningIndicators/InBlock.gif)
94
![](/Images/OutliningIndicators/InBlock.gif)
95
![](/Images/OutliningIndicators/InBlock.gif)
96
![](/Images/OutliningIndicators/InBlock.gif)
97
![](/Images/OutliningIndicators/InBlock.gif)
98
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
99
![](/Images/OutliningIndicators/InBlock.gif)
100
![](/Images/OutliningIndicators/InBlock.gif)
101
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
102
![](/Images/OutliningIndicators/InBlock.gif)
103
![](/Images/OutliningIndicators/InBlock.gif)
104
![](/Images/OutliningIndicators/InBlock.gif)
105
![](/Images/OutliningIndicators/InBlock.gif)
106
![](/Images/OutliningIndicators/InBlock.gif)
107
![](/Images/OutliningIndicators/InBlock.gif)
108
![](/Images/OutliningIndicators/InBlock.gif)
109
![](/Images/OutliningIndicators/InBlock.gif)
110
![](/Images/OutliningIndicators/InBlock.gif)
111
![](/Images/OutliningIndicators/InBlock.gif)
112
![](/Images/OutliningIndicators/InBlock.gif)
113
![](/Images/OutliningIndicators/InBlock.gif)
114
![](/Images/OutliningIndicators/InBlock.gif)
115
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
116
![](/Images/OutliningIndicators/InBlock.gif)
117
![](/Images/OutliningIndicators/InBlock.gif)
118
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
119
![](/Images/OutliningIndicators/InBlock.gif)
120
![](/Images/OutliningIndicators/InBlock.gif)
121
![](/Images/OutliningIndicators/InBlock.gif)
122
![](/Images/OutliningIndicators/InBlock.gif)
123
![](/Images/OutliningIndicators/InBlock.gif)
124
![](/Images/OutliningIndicators/InBlock.gif)
125
![](/Images/OutliningIndicators/InBlock.gif)
126
![](/Images/OutliningIndicators/InBlock.gif)
127
![](/Images/OutliningIndicators/InBlock.gif)
128
![](/Images/OutliningIndicators/InBlock.gif)
129
![](/Images/OutliningIndicators/InBlock.gif)
130
![](/Images/OutliningIndicators/InBlock.gif)
131
![](/Images/OutliningIndicators/InBlock.gif)
132
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
133
![](/Images/OutliningIndicators/InBlock.gif)
134
![](/Images/OutliningIndicators/InBlock.gif)
135
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
136
![](/Images/OutliningIndicators/InBlock.gif)
137
![](/Images/OutliningIndicators/InBlock.gif)
138
![](/Images/OutliningIndicators/InBlock.gif)
139
![](/Images/OutliningIndicators/InBlock.gif)
140
![](/Images/OutliningIndicators/InBlock.gif)
141
![](/Images/OutliningIndicators/InBlock.gif)
142
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
143
![](/Images/OutliningIndicators/InBlock.gif)
144
![](/Images/OutliningIndicators/InBlock.gif)
145
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
146
![](/Images/OutliningIndicators/InBlock.gif)
147
![](/Images/OutliningIndicators/InBlock.gif)
148
![](/Images/OutliningIndicators/InBlock.gif)
149
![](/Images/OutliningIndicators/InBlock.gif)
150
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
151
![](/Images/OutliningIndicators/InBlock.gif)
152
![](/Images/OutliningIndicators/InBlock.gif)
153
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
154
![](/Images/OutliningIndicators/InBlock.gif)
155
![](/Images/OutliningIndicators/InBlock.gif)
156
![](/Images/OutliningIndicators/InBlock.gif)
157
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
158
![](/Images/OutliningIndicators/InBlock.gif)
159
![](/Images/OutliningIndicators/InBlock.gif)
160
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
161
![](/Images/OutliningIndicators/InBlock.gif)
162
![](/Images/OutliningIndicators/InBlock.gif)
163
![](/Images/OutliningIndicators/InBlock.gif)
164
![](/Images/OutliningIndicators/InBlock.gif)
165
![](/Images/OutliningIndicators/InBlock.gif)
166
![](/Images/OutliningIndicators/InBlock.gif)
167
![](/Images/OutliningIndicators/InBlock.gif)
168
![](/Images/OutliningIndicators/InBlock.gif)
169
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
170
![](/Images/OutliningIndicators/InBlock.gif)
171
![](/Images/OutliningIndicators/InBlock.gif)
172
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
173
![](/Images/OutliningIndicators/InBlock.gif)
174
![](/Images/OutliningIndicators/InBlock.gif)
175
![](/Images/OutliningIndicators/InBlock.gif)
176
![](/Images/OutliningIndicators/InBlock.gif)
177
![](/Images/OutliningIndicators/InBlock.gif)
178
![](/Images/OutliningIndicators/InBlock.gif)
179
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
180
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
181
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
182
![](/Images/OutliningIndicators/None.gif)