是否可以设置默认值以在 DynamicControl 中显示?不是
Is it possible to set default value to display in DynamicControl? Not
在 asp.net webform 中,我有一个带有 DynamicControl 的 FormView。如何为 issuedDate 设置默认值?
<asp:FormView runat="server"....>
<InsertItemTemplate>
<asp:Label AssociatedControlID="issuedDate" runat="server">Issued date:</asp:Label>
<asp:DynamicControl runat="server" ID="issuedDate" DataField="IssuedDate" Mode="Edit" />
....
</InsertItemTemplate>
<EmptyDataTemplate>
<p>
No Data found.
</p>
</EmptyDataTemplate>
</asp:FormView>
尝试如下访问您的控件,
protected void ItemsFormView_DataBound(object sender, EventArgs e)
{
If (FormView1.CurrentMode == FormViewMode.Insert){
DataRowView dataRow = ((DataRowView)FormView1.DataItem);
if (Convert.ToInt16(dataRow["ClStk"]) <= 0)
{
Label lbl = (Label)FormView1.FindControl("lblStock");
lbl.CssClass = "changefont";
}
}
}
DynamicControl 无效。所以我使用 TextBox 而不是 DynamicControl。
<asp:TextBox runat="server" ID="IssuedDateTextBox" CssClass="form-control" Text='<%# Bind("IssuedDate") %>' />
已添加myForm_DataBound
protected void myForm_DataBound(object sender, EventArgs e)
{
if (myForm.CurrentMode == FormViewMode.Insert)
{
TextBox tb = (TextBox)myForm.FindControl("IssuedDateTextBox");
if (String.IsNullOrEmpty(tb.Text.Trim()))
{
//set default value - TODAY date
tb.Text = String.Format("{0:yyyy}{0:MM}{0:dd}", DateTime.Now);
}
}
}
在 asp.net webform 中,我有一个带有 DynamicControl 的 FormView。如何为 issuedDate 设置默认值?
<asp:FormView runat="server"....>
<InsertItemTemplate>
<asp:Label AssociatedControlID="issuedDate" runat="server">Issued date:</asp:Label>
<asp:DynamicControl runat="server" ID="issuedDate" DataField="IssuedDate" Mode="Edit" />
....
</InsertItemTemplate>
<EmptyDataTemplate>
<p>
No Data found.
</p>
</EmptyDataTemplate>
</asp:FormView>
尝试如下访问您的控件,
protected void ItemsFormView_DataBound(object sender, EventArgs e)
{
If (FormView1.CurrentMode == FormViewMode.Insert){
DataRowView dataRow = ((DataRowView)FormView1.DataItem);
if (Convert.ToInt16(dataRow["ClStk"]) <= 0)
{
Label lbl = (Label)FormView1.FindControl("lblStock");
lbl.CssClass = "changefont";
}
}
}
DynamicControl 无效。所以我使用 TextBox 而不是 DynamicControl。
<asp:TextBox runat="server" ID="IssuedDateTextBox" CssClass="form-control" Text='<%# Bind("IssuedDate") %>' />
已添加myForm_DataBound
protected void myForm_DataBound(object sender, EventArgs e)
{
if (myForm.CurrentMode == FormViewMode.Insert)
{
TextBox tb = (TextBox)myForm.FindControl("IssuedDateTextBox");
if (String.IsNullOrEmpty(tb.Text.Trim()))
{
//set default value - TODAY date
tb.Text = String.Format("{0:yyyy}{0:MM}{0:dd}", DateTime.Now);
}
}
}