Gridview:如何通过下拉列表刷新Timepicker值?

时间:2011-07-22 01:03:37

标签: asp.net gridview drop-down-menu timepicker

1

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

由于 乔

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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