473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Default values in a FormView

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

Feb 21 '06 #1
2 9033
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("chkDiscontinu ed");
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("chkDiscontinu ed");
if (chk != null)
{
e.Values["Discontinued"] = chk.Checked;
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Gary Homewood" wrote:
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

Feb 22 '06 #2

That's great, that's the method I eventually discovered and which seemed to
do the job. I was just hoping there would be some way for me to set the
default values declaratively, i.e. not having to resort to code.
"Phillip Williams" wrote:
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("chkDiscontinu ed");
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("chkDiscontinu ed");
if (chk != null)
{
e.Values["Discontinued"] = chk.Checked;
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Gary Homewood" wrote:
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

Feb 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Glass | last post by:
I'm working on an ASP.Net web app using VS2005 and the .Net 2.0 framework, and I have a serious problem with the page I'm currently working on. The page has, among other things, two FormViews and a...
0
by: Hawk | last post by:
Hi there, I am using a formview to see the details of a record in a gridview. When in edit mode in the formview and When update is pushed the fields that have values get erased? I deleted the...
0
by: Chris | last post by:
I am using the formview control. Within its edit template I have a treeview, which I populate programatically. Initially I had an item template in which I had a button, which triggered the edit...
0
by: Prakash | last post by:
Hi all, I am getting an error message "Object reference not set to an instance of an object." when i try to read values that are inside FormView control. I am just trying to read the values...
2
by: Matt MacDonald | last post by:
Hi all, I'm having an issue that's driving me crazy. I have a datatable that I need to display all the information for on a page. So, instead of manually coding every single column to a label, I...
2
by: COHENMARVIN | last post by:
I have a formview control, with labels arranged in a table. The labels are bound to fields from a query. But I also want to sum up the values in the table and put them in a row of totals at the...
3
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, has anyone ever bound data to a formview that's in Insert Mode? For example, if you had to get default values from the database for a new record? thanks, rodchar
4
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
5
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls In a ASP.Net form I have 20 textboxes and 20 dropdownlists(ddl). All ddl(s) are databound and get...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.