在edititemtemplate标签vb.net上更新TimeRecorded

时间:2014-01-31 12:57:57

标签: vb.net edititemtemplate

我正在尝试在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>

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

编写此代码:

Dim lblFtrTimeRecorded As Label = GridView1.Rows[GridView1.EditIndex].FindControl("lblFtrTimeRecorded")
lblFtrTimeRecorded.Text = Date.Now