ASP:VB.NET中的Repeater

时间:2017-07-12 15:22:24

标签: sql asp.net vb.net repeater

我正在使用Visual Studio! (telerik就像gridview,同样的东西) 我想慢慢地试图用ASP创建一个调度程序:Repeater !!! 有人请救我脱离这种永无止境的折磨!洛尔

目标:这是患者预约的页面!因此,该页面有一个网格,显示文档的信息及其可用性(TimeSlot)! [请参阅附图]

---。ASPX ---- 下面是ASPX代码(正面)

<telerik:RadGrid ID="RadGrid_provider_details" runat="server" DataSourceID="SDS_provider_detail"
                        Height="700px" Skin="Metro" Width="100%" PageSize="3" AutoGenerateColumns="false">
                        <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
                        <MasterTableView DataSourceID="SDS_provider_detail" Font-Size="Large" DataKeyNames="provider_code">
                            <NoRecordsTemplate>
                                There is no result with the selected filter.
                            </NoRecordsTemplate>
                        <Columns>
                            <telerik:GridBoundColumn DataField="providerFullName" HeaderStyle-Width="15%" ItemStyle-Height="200px"
                                HeaderText="Name" ReadOnly="True" SortExpression="providerFullName" UniqueName="providerFullName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="taxonomy_desc" HeaderText="Specialty" ReadOnly="True"
                                SortExpression="taxonomy_desc" HeaderStyle-Width="15%">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="addr1" HeaderText="Address" ReadOnly="True" SortExpression="addr1"
                                HeaderStyle-Width="15%">
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn>
                                <ItemTemplate>
                                    <asp:Repeater ID="Repeater_appt" runat="server" DataSourceID="SDS_Repeater_appt">
                                        <ItemTemplate>
                                            <%--<asp:Label runat="server" ID="lbl_appt" Text="YEAH"></asp:Label>--%>
                                            <asp:Button runat="server" ID="btn_haha" Text='<%# Eval("timeslot") %>' Font-Size="Large"
                                                Width="100px" />
                                        </ItemTemplate>
                                    </asp:Repeater>
                                    <asp:Button runat="server" ID="btn_more_appt" Text="More" Font-Size="Large" Width="100px" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>

                        </Columns>
                        <ItemStyle CssClass="item-style" />
                        <AlternatingItemStyle CssClass="item-style" />
                    </MasterTableView>
                    <ClientSettings>
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" ScrollHeight="650px"></Scrolling>
                    </ClientSettings>
                </telerik:RadGrid>
                <asp:SqlDataSource ID="SDS_Repeater_appt" runat="server"></asp:SqlDataSource>
                <asp:SqlDataSource ID="SDS_provider_detail" runat="server">
                    <SelectParameters>
                    </SelectParameters>
                </asp:SqlDataSource>

---。VB -----

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports Telerik.Web.UI
Partial Class Appointment
    Inherits System.Web.UI.Page

  Protected Sub RadGrid_provider_details_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid_provider_details.ItemDataBound
    'This sub gets activated so I can get the provider-code for the providers...I don't get it too well
    'The provider code is required to get the availability for the doctors, and it is from the datasource of the grid
    'Here is also where I call the BindRepeater_retrieveTimeSlotAvailbility() '

        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
            Dim provider_code As String = item.GetDataKeyValue("provider_code").ToString()

            Dim item2 As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim Repeater_appt As Repeater = DirectCast(item2.FindControl("Repeater_appt"), Repeater)

            BindRepeater_retrieveTimeSlotAvailbility(provider_code, Repeater_appt)

        End If

    End Sub


Private Sub BindRepeater_retrieveTimeSlotAvailbility(ByVal provider_code As String, ByRef Repeater_appt As Repeater)
        initializeScheduler()

        Dim SQlstr As String, RtnStr As String
        Dim selected_org_code As String = ""
        selected_org_code = DDL_Clinic.SelectedValue
        HF_OrgCode.Value = selected_org_code
        Dim connectionStr As String = ""
        connectionStr = GetClientConnectionStringByOrgCode(selected_org_code)
        Dim errormsg As String = ""
        SQlstr = "select office_location from locations where facility_name= '" & DDL_Clinic.SelectedItem.Text & "'"
        Dim office_location As String = PubFunc.SelectOneBySQL2(SQlstr, connectionStr, errormsg)
        If errormsg <> "" Then
            MessageDisplayInModal(errormsg, True)
        End If

        If provider_code <> "" Then
            Dim In_String As String = "'0',"
            In_String &= "'" & provider_code & "'," & "'0'"
            '===========================

            Dim dateToSchedule As DateTime
            dateToSchedule = txt_DateToSchedule.Text
            dateToSchedule.ToShortDateString()


            time_slot_SQL2(SQlstr, dateToSchedule.ToShortDateString(), office_location, RtnStr, In_String, day_start, day_end)


            ''Added by HELPER, but I didn't get it.. it gives me a 'Both datasource and datasourceID are defined on 'Repeater_appt' Remove one definition' error
            'Execute SQlstr and get datatable.
            'Datatable dt = Result of SQlstr
            'Repeater_appt.DataSource = SQlstr
            'Repeater_appt.DataBind()

            SDS_Repeater_appt.SelectCommand = SQlstr
            SDS_Repeater_appt.ConnectionString = connectionStr
            SDS_Repeater_appt.DataBind()
        End If

 Protected Sub time_slot_SQL2(ByRef SQLStr As String, ByVal dateToSchedule As String, ByVal office_location As String, ByVal RtnStr As String, ByVal In_String As String, ByVal day_start As String, ByVal day_end As String)
'The original sql is super long, basically, just return the SQLstr (byRef) to where it calls it! (just to make code neater)
        SQLStr = "SELECT TOP 5 timeslot from appt where provider_code = '100'"

End Sub
End Class

&#39;运行代码时发生的事情的结果: 测试数据:假设有3个测试提供者(provider1,provider2,provider3;他们都有diff TIMESLOT)

代码运行:

  1. 调用RadGrid_provider_details_ItemDataBound一次; e.item不是 GridDataItem,因此它退出sub
  2. 再次调用ItemDataBound,e.item是GridDataItem,获取provider1 providercode它遍历代码,并调用BindRepeater_retrieveTimeSlotAvailbility(provider_code,repeater_appt)
  3. 再次调用ItemDataBound,e.item不是GridDataItem,因此退出 子
  4. 前往(aspx),EVAL(时间段)5次
  5. 再次调用ItemDataBound,e.item是GridDataItem,provider2的providercode2,并通过
  6. 再次调用ItemDataBound,e.item不是GridDataItem,因此退出 子
  7. 再次回到前面(aspx)并运行5次
  8. 再次调用ItemDataBound,e.item是GridDataItem,provider3的providercode3,并通过
  9. 再次调用ItemDataBound,e.item不是GridDataItem,因此退出 子
  10. 再次调用ItemDataBound,e.item不是GridDataItem,因此退出  子
  11. RadGrid_provider_detail.databind()
  12. 再次回到前面(aspx),跑了15次并完成......
  13. 提前致谢!!!!!!

0 个答案:

没有答案