0

ユーザーが編集リンクボタンをクリックしたときに、グリッドビューの edititemtemplate のラベルに現在の日付と時刻を表示しようとしています。date.now をデータ バインディング ボックスに入れると、目的の結果が表示されますが、[更新] をクリックすると、フィールドを null にすることはできないというエラーが表示されます。フッター行で試してみるとうまくいきますが、編集行ではうまくいきません。動作するフッター行コードは次のとおりです。

'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 に答える