我有一个问题,我想从后面的代码中将一个数据集与 aspx 表单中的标签绑定,并且我在一个函数中使用了 2 个数据集,但问题是它只绑定了第一个数据集。
我的代码是这样的:
private void fill()
{
DateTime dat;
if (txtDate.Text == "")
dat = DateTime.Now;
else
dat = DateTime.ParseExact(txtDate .Text , "M/d/yyyy", null);
rtbl.LoadRoomTypes(_ds, SessionContext.PropertyID,dat);
dlDashBoard.DataSource = _ds.Tables[rtbl.SqlEntityX];
dlDashBoard.DataBind();
foreach(DataListItem item in dlDashBoard .Items )
{
BindNestedItem(item.ItemIndex );
}
_ds = null;
RoomTypeBAL rtbl1 = new RoomTypeBAL(0);
rtbl1.LoadTotalFree(_ds3, SessionContext.PropertyID, dat);
if(_ds3 !=null && _ds3.Tables[rtbl1 .SqlEntityX ].Rows.Count >0)
this.DataBind();//Problem is here binding _ds always but I want to bind _ds3
}
我的来源是这样的:
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="FreeRooms :"></asp:Label>
</td>
<td>
<asp:Label ID="lblfreeRoom1" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tfreeroom1"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblfreeRoom2" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tfreeroom2"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblfreeRoom3" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tfreeroom3"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblfreeRoom4" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tfreeroom4"].ToString()%>'></asp:Label>
</td>
<td>
<asp:Label ID="lblfreeRoom5" runat="server" Text='<%#_ds3.Tables[0].Rows[0]["tfreeroom5"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblfreeRoom6" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tfreeroom6"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tfreeroom7"].ToString() %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Arrivals :"></asp:Label>
</td>
<td>
<asp:Label ID="Label4" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tarrival1"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label5" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tarrival2"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label6" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tarrival3"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label7" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tarrival4"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label8" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tarrival5"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label9" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tarrival6"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label10" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tarrival7"].ToString() %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label11" runat="server" Text="CheckOuts :"></asp:Label>
</td>
<td>
<asp:Label ID="Label12" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tcheckout1"].ToString()%>'></asp:Label>
</td>
<td>
<asp:Label ID="Label13" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tcheckout2"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label14" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tcheckout3"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label15" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tcheckout4"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label16" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tcheckout5"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label17" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tcheckout6"].ToString() %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label18" runat="server" Text='<%# _ds3.Tables[0].Rows[0]["tcheckout7"].ToString() %>'></asp:Label>
</td>
</tr>
</table>