在asp.net gridview中动态创建列

时间:2011-07-21 14:24:27

标签: asp.net gridview

我正在做酒店项目。在该预订页面中,所有房型及其可用性及其费率必须在给定日期的网格视图中填充。

以下是酒店管理页面中的房型。

enter image description here

下面的图片是给定日期的约束房价。 enter image description here

目前我通过对每个单元格使用sql查询来绑定数据。因此加载页面需要花费很多时间。

我需要一个帮助来找到一种更快的方法来绑定数据。

我使用的代码如下所示。

dim DTX AS new datatable
  

/// sql命令加载roomtypes。

While DR.Read
DTR = DTX.NewRow()
Dim datearray() As String = lbl_CheckInDate.Text.Split("/")
Dim XDT1 As New Date(CInt(datearray(2)), CInt(datearray(0)), CInt(datearray(1)))
DTR("Room Type") = DR("r_type").ToString
DTR("Book") = DR("r_id").ToString
     For x = 1 To 15
    tmpdt = Left(WeekdayName(Weekday(XDT1)), 3) & vbNewLine & Day(XDT1) & " " & Left(MonthName(Month(XDT1)), 3)
     price = Cls_function.GetTableData("select isnull(rent_a,0) as rent_a from tbl_HotelRoom where H_ID = " & Val(Request.QueryString("HID")) & " and r_id = " & Val(DR("r_id").ToString) & " and f_dt <= '" & Year(XDT1) & "-" & Month(XDT1) & "-" & Day(XDT1) & "' and t_dt >= '" & Year(XDT1) & "-" & Month(XDT1) & "-" & Day(XDT1) & "'")

If price = Nothing Then
        DTR(tmpdt) = Cls_function.GetTableData("select isnull(rent_a,0) as rent_a from tbl_HotelRoom where H_ID = " & Val(Request.QueryString("HID")) & " and r_id = " & Val(DR("r_id").ToString) & " and f_dt <= '" & Year(XDT1) & "-" & Month(XDT1) & "-" & Day(XDT1) & "' and t_dt >= '" & Year(XDT1) & "-" & Month(XDT1) & "-" & Day(XDT1) & "'")

Else
   DTR(tmpdt) = Format(price, "N")
End If
 XDT1 = DateAdd(DateInterval.Day, 1, XDT1)
Next
DTX.Rows.Add(DTR)

1 个答案:

答案 0 :(得分:0)

虽然不完全清楚,但我猜你要为每个日期调用数据库来获得房价。更好的方法是编写存储过程以返回给定房间类型的下一个X日期的房价。如果你的sproc将数据作为多行返回(而不是一行有很多列,那将是比较棘手的SQL),那么你可以做一些业务逻辑操作来获得你需要的格式数据,以便轻松地将它绑定到网格。 / p>