Handle the ItemCreated event of the FormView and set the checkbox.checked to
true if the CurrentMode is Insert, e.g.
void FormView1_ItemCreated(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Insert)
{
CheckBox chk =
(CheckBox)FormView1.Row.FindControl("chkDiscontinued");
if (chk != null)
{
chk.Checked = true;
}
}
}
Another alternative is to remove the Bind method from the checkbox.Checked
property and set it to True within the InsertTemplate, and then upon
ItemInserting you would set the value as decided by the user, e.g.
void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
{
CheckBox chk = (CheckBox)FormView1.Row.FindControl("chkDiscontinued");
if (chk != null)
{
e.Values["Discontinued"] = chk.Checked;
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
Gary Homewood said:
Where can I specify a default value for a column when using a FormView?
Specifically, I have a checkbox for a column of bit datatype on my database,
and I'd like to default it to checked for insert of a new row.
Thanks,
Gary