0

我试图在我的gridview 的edititemtemplate 中有一个标签显示用户单击编辑链接按钮时的当前日期和时间。当我将 date.now 放入数据绑定框中时,我可以看到我想要的结果,但是当我单击更新时,我得到一个字段不能为空的错误。当我尝试对页脚行而不是编辑行时,它工作正常。这是有效的页脚行代码:

'Get Time Recorded
Dim lblFtrTimeRecorded As Label = GridView1.FooterRow.FindControl("lblFtrTimeRecorded")
lblFtrTimeRecorded.Text = Date.Now

这是模板字段 .aspx 代码:

        <asp:TemplateField HeaderText="TimeRecorded" SortExpression="TimeRecorded">
            <EditItemTemplate>
                <asp:Label ID="lblEditTimeRecorded" runat="server" 
                    Text='<%# Bind("TimeRecorded") %>'></asp:Label>
            </EditItemTemplate>
            <FooterTemplate>
                <asp:Label ID="lblFtrTimeRecorded" runat="server"></asp:Label>
            </FooterTemplate>
            <ItemTemplate>
                <asp:Label ID="lblTimeRecorded" runat="server" 
                    Text='<%# Bind("TimeRecorded") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

任何帮助是极大的赞赏!

4

1 回答 1

0

写下这段代码:

Dim lblFtrTimeRecorded As Label = GridView1.Rows[GridView1.EditIndex].FindControl("lblFtrTimeRecorded")
lblFtrTimeRecorded.Text = Date.Now
于 2014-01-31T13:06:51.473 回答