读书人

(100分有关问题) DetailsView 新建时如

发布时间: 2012-02-08 19:52:21 作者: rapoo

(100分问题) DetailsView 新建时怎么才能显示默认值
情况是这样的 . 需要插入一条记录 . 记录里面有时间 .
我想能否新建的时候直接输时间到那里面 .

或者在时间那行里面做个提示也可以 .
因为我已经在 DetailsView的ItemInserting 事件里面写入 e.Values[n] = DateTime.Now.ToString(); 了



[解决办法]
转为模板字段,然后编辑模板字段输入框.
[解决办法]
http://www.cnblogs.com/ldarmy/articles/913242.html
[解决办法]
如果是我理解那样的话,那很容易啊,
绑日期不是吗?

=============================================================
<asp:TemplateField HeaderText="aaa" SortExpression="compcd">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("compcd") %>'></asp:Label>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("compcd") %>' OnInit="TextBox1_Init"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("compcd") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

----------------------------------
protected void TextBox1_Init(object sender, EventArgs e)
{
((TextBox)sender).Text = DateTime.Now.ToShortDateString();
}
[解决办法]
我喜欢直接在数据库里引用服务器的时间,不知道这样好不好。

读书人网 >asp.net

热点推荐