从前面往后面写:
ascx:
1<asp:datagrid id="grdTopics" Runat="server" GridLines="None" CellPadding="2" AutoGenerateColumns="false"
2 width="100%" cssclass="DataGrid_Container">
3 <FooterStyle CssClass="DataGrid_Footer"></FooterStyle>
4 <SelectedItemStyle CssClass="NormalRed"></SelectedItemStyle>
5 <EditItemStyle CssClass="NormalTextBox"></EditItemStyle>
6 <AlternatingItemStyle CssClass="Normal"></AlternatingItemStyle>
7 <ItemStyle HorizontalAlign="Left" CssClass="Normal"></ItemStyle>
8 <HeaderStyle HorizontalAlign="Center" CssClass="NormalBold" VerticalAlign="Top"></HeaderStyle>
9 <Columns>
10 <asp:TemplateColumn HeaderText="Selected">
11 <ItemTemplate>
12 <input type="checkbox" width="10" name="chkid" value='<%# DataBinder.Eval(Container.DataItem, "TopicID")%>' onclick='UnCheck(this)' style="background-color:transparent" >
13 </ItemTemplate>
14 </asp:TemplateColumn>
15 <dnn:TextColumn HeaderText="TopicId" DataField="TopicId" Width="50">
16 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
17 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
18 <HeaderTemplate></HeaderTemplate>
19 <ItemTemplate></ItemTemplate>
20 <EditItemTemplate></EditItemTemplate>
21 </dnn:TextColumn>
22 <dnn:TextColumn HeaderText="Title" DataField="inTitle" Width="">
23 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
24 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
25 <HeaderTemplate></HeaderTemplate>
26 <ItemTemplate></ItemTemplate>
27 <EditItemTemplate></EditItemTemplate>
28 </dnn:TextColumn>
29 <dnn:TextColumn HeaderText="Summary" DataField="inSummary" Width="50">
30 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
31 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
32 <HeaderTemplate></HeaderTemplate>
33 <ItemTemplate></ItemTemplate>
34 <EditItemTemplate></EditItemTemplate>
35 </dnn:TextColumn>
36 <dnn:TextColumn HeaderText="Guests" DataField="inGuests" Width="">
37 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
38 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
39 <HeaderTemplate></HeaderTemplate>
40 <ItemTemplate></ItemTemplate>
41 <EditItemTemplate></EditItemTemplate>
42 </dnn:TextColumn>
43 <dnn:TextColumn HeaderText="Time" DataField="inTime" Width="">
44 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
45 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
46 <HeaderTemplate></HeaderTemplate>
47 <ItemTemplate></ItemTemplate>
48 <EditItemTemplate></EditItemTemplate>
49 </dnn:TextColumn>
50 <dnn:TextColumn HeaderText="ImgUrl" DataField="inImgUrl" Width="">
51 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
52 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
53 <HeaderTemplate></HeaderTemplate>
54 <ItemTemplate></ItemTemplate>
55 <EditItemTemplate></EditItemTemplate>
56 </dnn:TextColumn>
57 <dnn:ImageCommandColumn KeyField="TopicId" ShowImage="True" ImageURL="images/edit.gif" CommandName="Edit"
58 EditMode="URL">
59 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Center"></HeaderStyle>
60 <EditItemTemplate></EditItemTemplate>
61 <ItemStyle HorizontalAlign="Center"></ItemStyle>
62 <HeaderTemplate></HeaderTemplate>
63 <ItemTemplate></ItemTemplate>
64 </dnn:ImageCommandColumn>
65 <dnn:ImageCommandColumn KeyField="TopicId" ShowImage="True" ImageURL="images/delete.gif" CommandName="Delete"
66 EditMode="Command">
67 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Center"></HeaderStyle>
68 <EditItemTemplate></EditItemTemplate>
69 <ItemStyle HorizontalAlign="Center"></ItemStyle>
70 <HeaderTemplate></HeaderTemplate>
71 <ItemTemplate></ItemTemplate>
72 </dnn:ImageCommandColumn>
73 </Columns>
74 <PagerStyle CssClass="DataGrid_Pager"></PagerStyle>
75</asp:datagrid>
2 width="100%" cssclass="DataGrid_Container">
3 <FooterStyle CssClass="DataGrid_Footer"></FooterStyle>
4 <SelectedItemStyle CssClass="NormalRed"></SelectedItemStyle>
5 <EditItemStyle CssClass="NormalTextBox"></EditItemStyle>
6 <AlternatingItemStyle CssClass="Normal"></AlternatingItemStyle>
7 <ItemStyle HorizontalAlign="Left" CssClass="Normal"></ItemStyle>
8 <HeaderStyle HorizontalAlign="Center" CssClass="NormalBold" VerticalAlign="Top"></HeaderStyle>
9 <Columns>
10 <asp:TemplateColumn HeaderText="Selected">
11 <ItemTemplate>
12 <input type="checkbox" width="10" name="chkid" value='<%# DataBinder.Eval(Container.DataItem, "TopicID")%>' onclick='UnCheck(this)' style="background-color:transparent" >
13 </ItemTemplate>
14 </asp:TemplateColumn>
15 <dnn:TextColumn HeaderText="TopicId" DataField="TopicId" Width="50">
16 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
17 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
18 <HeaderTemplate></HeaderTemplate>
19 <ItemTemplate></ItemTemplate>
20 <EditItemTemplate></EditItemTemplate>
21 </dnn:TextColumn>
22 <dnn:TextColumn HeaderText="Title" DataField="inTitle" Width="">
23 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
24 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
25 <HeaderTemplate></HeaderTemplate>
26 <ItemTemplate></ItemTemplate>
27 <EditItemTemplate></EditItemTemplate>
28 </dnn:TextColumn>
29 <dnn:TextColumn HeaderText="Summary" DataField="inSummary" Width="50">
30 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
31 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
32 <HeaderTemplate></HeaderTemplate>
33 <ItemTemplate></ItemTemplate>
34 <EditItemTemplate></EditItemTemplate>
35 </dnn:TextColumn>
36 <dnn:TextColumn HeaderText="Guests" DataField="inGuests" Width="">
37 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
38 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
39 <HeaderTemplate></HeaderTemplate>
40 <ItemTemplate></ItemTemplate>
41 <EditItemTemplate></EditItemTemplate>
42 </dnn:TextColumn>
43 <dnn:TextColumn HeaderText="Time" DataField="inTime" Width="">
44 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
45 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
46 <HeaderTemplate></HeaderTemplate>
47 <ItemTemplate></ItemTemplate>
48 <EditItemTemplate></EditItemTemplate>
49 </dnn:TextColumn>
50 <dnn:TextColumn HeaderText="ImgUrl" DataField="inImgUrl" Width="">
51 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Left"></HeaderStyle>
52 <ItemStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" HorizontalAlign="Left"></ItemStyle>
53 <HeaderTemplate></HeaderTemplate>
54 <ItemTemplate></ItemTemplate>
55 <EditItemTemplate></EditItemTemplate>
56 </dnn:TextColumn>
57 <dnn:ImageCommandColumn KeyField="TopicId" ShowImage="True" ImageURL="images/edit.gif" CommandName="Edit"
58 EditMode="URL">
59 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Center"></HeaderStyle>
60 <EditItemTemplate></EditItemTemplate>
61 <ItemStyle HorizontalAlign="Center"></ItemStyle>
62 <HeaderTemplate></HeaderTemplate>
63 <ItemTemplate></ItemTemplate>
64 </dnn:ImageCommandColumn>
65 <dnn:ImageCommandColumn KeyField="TopicId" ShowImage="True" ImageURL="images/delete.gif" CommandName="Delete"
66 EditMode="Command">
67 <HeaderStyle Font-Size="10pt" Font-Names="Tahoma, Verdana, Arial" Font-Bold="True" HorizontalAlign="Center"></HeaderStyle>
68 <EditItemTemplate></EditItemTemplate>
69 <ItemStyle HorizontalAlign="Center"></ItemStyle>
70 <HeaderTemplate></HeaderTemplate>
71 <ItemTemplate></ItemTemplate>
72 </dnn:ImageCommandColumn>
73 </Columns>
74 <PagerStyle CssClass="DataGrid_Pager"></PagerStyle>
75</asp:datagrid>
下面就有问题了:
.ascx.cs:
1private void BindData()
2 {
3
8 ChatRoomController ctl1 = new ChatRoomController();
9 TopicsInfo info1 = ctl1.GetTopics(this.ModuleId);//这里得到所有的topic,数组形式,调试时可以将info1里面的内容输出:
TopicInfo aa = (TopicInfo)info1.Topics[0];
Response.Write(info1.Count.ToString() +aa.inTitle);
26 this.grdTopics.DataSource = info1.Topics;
28 this.grdTopics.DataBind();
29 this.BindPages();
30 this.ProessButton();
31 }
最大的错误出现在controller里面:2 {
3
8 ChatRoomController ctl1 = new ChatRoomController();
9 TopicsInfo info1 = ctl1.GetTopics(this.ModuleId);//这里得到所有的topic,数组形式,调试时可以将info1里面的内容输出:
TopicInfo aa = (TopicInfo)info1.Topics[0];
Response.Write(info1.Count.ToString() +aa.inTitle);
26 this.grdTopics.DataSource = info1.Topics;
28 this.grdTopics.DataBind();
29 this.BindPages();
30 this.ProessButton();
31 }
1public TopicsInfo GetTopics(int ModuleID)
2 {
3 TopicsInfo info1 = new TopicsInfo();
4 ArrayList list1 = new ArrayList();
5 IDataReader reader1 = DataProvider.Instance().GetTopics(ModuleID);
6 reader1.Read();
7 int num1 = Convert.ToInt32(RuntimeHelpers.GetObjectValue(reader1[0]));
8 reader1.NextResult();
9 list1 = CBO.FillCollection(reader1, typeof(TopicInfo));
10 info1.Count = num1;
11 info1.Topics = list1;
12 return info1;
13 }
由于对 IDataReader reader1 = DataProvider.Instance().GetTopics(ModuleID); reader1.Read();2 {
3 TopicsInfo info1 = new TopicsInfo();
4 ArrayList list1 = new ArrayList();
5 IDataReader reader1 = DataProvider.Instance().GetTopics(ModuleID);
6 reader1.Read();
7 int num1 = Convert.ToInt32(RuntimeHelpers.GetObjectValue(reader1[0]));
8 reader1.NextResult();
9 list1 = CBO.FillCollection(reader1, typeof(TopicInfo));
10 info1.Count = num1;
11 info1.Topics = list1;
12 return info1;
13 }
不熟悉,所以犯错误了,现在详细的认识一下这个idatareader :
通过存储过程gettopic读出来所有的数据库中的数据,reader[0]是第一个数组中的内容。
reader1.NextResult();读下一个数组。
num1得到了reader[0],即topic的个数(在存储过程里面很清楚,一共select了两个数据,一个是topic个数,一个是topic的内容)
然后 info1.count = num1。
info1.topics = list1(即reader读的第二条数据 reader1.NextResult(),topic的内容)
以下是存储过程:
1SELECT COUNT([TopicId])
2 FROM dbo.HVC_ChatRoom_TopicsList
3 WHERE ModuleID = @ModuleID
4
5 SELECT
6 TopicId,
7 inTitle,
8 inSummary,
9 inTime,
10 inGuests
11 FROM {databaseOwner}{objectQualifier}HVC_ChatRoom_TopicsList
12 WHERE ModuleID = @ModuleID
2 FROM dbo.HVC_ChatRoom_TopicsList
3 WHERE ModuleID = @ModuleID
4
5 SELECT
6 TopicId,
7 inTitle,
8 inSummary,
9 inTime,
10 inGuests
11 FROM {databaseOwner}{objectQualifier}HVC_ChatRoom_TopicsList
12 WHERE ModuleID = @ModuleID