现在这真的令人沮丧。
我在gridview标记上有这个隐藏字段:
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="dhide" Value='<%# Eval("shipDates","{0:M/dd/yyyy}") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
然后在codebehind上,我试图检索dhide的值:
Sub cancelIt_Click(ByVal sender As Object,ByVal e As System.EventArgs) Dim objConnection As SqlConnection
Dim DLdates As HiddenField = DirectCast(GridView1.FindControl("dhide"), HiddenField)
Response.write (DLdates)
我做错了什么?
答案 0 :(得分:0)
它的NamingContainer
不是GridView
,而是它所在的GridViewRow
。
所以:
For Each row As GridViewRow In GridView1.Rows
Dim dhide = DirectCast(row.FindControl("dhide"), HiddenField)
Dim shipDates = Date.ParseExact(dhide.Value, "M/dd/yyyy", Nothing)
' ...
Next