0

1

在我的 gridview 中,我使用 MKB Timepicker 让用户输入时间。现在我想在gridview中添加一个下拉列表,当用户选择下拉列表时,它会自动刷新timepicker值(开始时间,结束时间)。但我不知道如何在行更新/编辑模板时刷新值。请帮忙。

谢谢乔

ASP 代码:

<EditItemTemplate>
<asp:DropDownList ID="ddl1_shifttype" runat ="server"  AutoPostBack ="true" DataSourceID="SqlDataSource2" DataTextField ="en_name" DataValueField ="shift_type_key" SelectedValue='<%# Bind("Col1_ShiftType") %>' OnSelectedIndexChanged ="ddl1_shifttype_SelectedIndexChanged"></asp:DropDownList>
From:
<MKB:TimeSelector ID="Col1_StartTime" runat="server" DisplaySeconds="False" MinuteIncrement="1"  BorderColor="Silver" 
                            Date="" SelectedTimeFormat="Twelve" 
                            Hour='<%#DataBinder.Eval(Container.DataItem, "Col1_StartTimeHr")%>' 
                            Minute ='<%#DataBinder.Eval(Container.DataItem, "Col1_StartTimeMin")%>'
                            AmPm ='<%#DataBinder.Eval(Container.DataItem, "Col1_StartTimeAMPM")%>'></MKB:TimeSelector>
To:
<MKB:TimeSelector ID="Col1_EndTime" runat="server" DisplaySeconds="False"  MinuteIncrement="1" BorderColor="Silver" 
                            Date="" SelectedTimeFormat="Twelve"                                 
                            Hour='<%#DataBinder.Eval(Container.DataItem, "Col1_EndTimeHr")%>' 
                            Minute ='<%#DataBinder.Eval(Container.DataItem, "Col1_EndTimeMin")%>'
                            AmPm ='<%#DataBinder.Eval(Container.DataItem, "Col1_EndTimeAMPM")%>'></MKB:TimeSelector>                                 
</EditItemTemplate> 

SelectIndexChange 事件:

Protected Sub ddl1_shifttype_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1_shifttype.SelectedIndexChanged
'Testing
    Col1_StartTime.Hour = "09"
    Col1_StartTime.Minute = "33"
    Col1_StartTime.AmPm = TimeSelector.AmPmSpec.PM        
End Sub
4

2 回答 2

0

问题解决了。以下是代码:

Protected Sub ddl1_shifttype_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1_shifttype.SelectedIndexChanged
    Dim var As String = DirectCast(sender, DropDownList).SelectedValue
    Dim tm1 As TimeSelector = DirectCast(DirectCast(sender, DropDownList).Parent.Parent.FindControl("Col1_StartTime"), TimeSelector)
    Dim tm2 As TimeSelector = DirectCast(DirectCast(sender, DropDownList).Parent.Parent.FindControl("Col1_EndTime"), TimeSelector)
    Dim cmd As New System.Data.SqlClient.SqlCommand
    Dim sql As String
    Dim reader As System.Data.SqlClient.SqlDataReader
    Dim ST As DateTime
    Dim ET As DateTime

    lb_ddl1.Text = var

    Using conn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("hris_shiftdutyConnectionString").ConnectionString)
        conn.Open()
        cmd.Connection = conn
        sql = "SELECT * from Tshift_type where shift_type_key='" & var & "';"
        cmd.CommandText = sql
        reader = cmd.ExecuteReader()
        If reader.Read() Then
            ST = reader("start_time")
            ET = reader("end_time")
        End If

        conn.Close()
        reader.Close()
    End Using

    If ST.Hour > 12 Then
        tm1.Hour = ST.Hour - 12
        tm1.AmPm = TimeSelector.AmPmSpec.PM
    Else
        tm1.Hour = ST.Hour
        tm1.AmPm = TimeSelector.AmPmSpec.AM
    End If
    tm1.Minute = ST.Minute

    If ET.Hour > 12 Then
        tm2.Hour = ET.Hour - 12
        tm2.AmPm = TimeSelector.AmPmSpec.PM
    Else
        tm2.Hour = ET.Hour
        tm2.AmPm = TimeSelector.AmPmSpec.AM
    End If
    tm2.Minute = ET.Minute

    'Dropdownlists = 'Select'
    If var = 0 Then
        tm1.Hour = "12"
        tm1.Minute = "00"
        tm1.AmPm = TimeSelector.AmPmSpec.AM
        tm2.Hour = "12"
        tm2.Minute = "00"
        tm2.AmPm = TimeSelector.AmPmSpec.AM
    End If

End Sub
于 2011-07-26T07:32:45.947 回答
0

在 DropDownList SelectedIndexChanged 事件中,编写代码以使用 FindControl 刷新 TimePicker。

于 2011-07-22T05:07:37.727 回答