gpt4 book ai didi

c# - 如何从 gridview 中的 TimeSelector 检索时间?

转载 作者:太空宇宙 更新时间:2023-11-03 16:36:12 29 4
gpt4 key购买 nike

我有一个 gridview,里面有一个 TimeSelector,但是我要如何从 gridview 中检索时间,因为如果通常它是一个 TextBox,我们将使用这个

Dim rbSelect As TextBox = DirectCast(GridView2.Cells(1).FindControl("TextBox"), TextBox)

那么我应该如何从 gridview 中的时间选择器中检索时间呢?

时间选择器控件: <%@ Register Assembly="TimePicker"Namespace="MKB.TimePicker"TagPrefix="cc1"%>

<ItemTemplate>
<table style="width: 79%; height: 31px;">

<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Time to start:"></asp:Label>
</td>
<td>
<cc1:TimeSelector ID="TimeSelector3" runat="server" AllowSecondEditing="false" DisplaySeconds="False" Height="25px" MinuteIncrement="15" Width="150px" />
</td>
</tr>

<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
</td>
</tr>

</table>
</ItemTemplate>
<ControlStyle Width="100px" />
<ItemStyle Width="210px" />
</asp:TemplateField>

最佳答案

所以这里有一些信息可以告诉你如何做到这一点:

  1. 添加对 TimePicker.dll 的引用。查看更多相关信息here .我刚才的选择器是this

  2. 在您正在工作的 aspx 页面上写入您的内容。要查看有关如何制定注册标签的更多信息,请参阅 this :
    <%@ Register Assembly="TimePicker" Namespace="MKB.TimePicker" TagPrefix="mkb"%>

  3. 使用TimePicker又名 TimeSelector (我知道这一点是因为我查看了 .net 反射器中的 dll,请参阅 this)。你需要一个ScriptManager每页。
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

  4. 要在页面上使用控件,请写入:
    <mkb:TimeSelector ID="TimeSelector1" runat="server"></mkb:TimeSelector>

这就是您添加单个 TimeSelector 的方式到你的页面。

这是 TimeSelector 的完整示例在 GridView 中:

Default.aspx

<%@ Register Assembly="TimePicker" Namespace="MKB.TimePicker" TagPrefix="mkb"%>
<%@ Page Title="Home Page" Language="vb" AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:GridView ID="gvTest" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<mkb:TimeSelector ID="TimeSelector1" runat="server"></mkb:TimeSelector>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>

Default.aspx.vb

Public Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ls As New List(Of String)()
ls.Add("Test")
ls.Add("Test2")
gvTest.DataSource = ls
gvTest.DataBind()
End Sub

Private Sub gvTest_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvTest.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim picker As MKB.TimePicker.TimeSelector = DirectCast(e.Row.FindControl("TimeSelector1"), MKB.TimePicker.TimeSelector)
End If
End Sub
Private Sub Save()
For Each row As GridViewRow In gvTest.Rows
Dim picker As MKB.TimePicker.TimeSelector = DirectCast(row.FindControl("TimeSelector1"), MKB.TimePicker.TimeSelector)
Next
End Sub
End Class

关于c# - 如何从 gridview 中的 TimeSelector 检索时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9052869/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com