473,569 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set default text on databound object

I have an insert template textbox that is bound to a field in SQL.
Since it is the insert template it really doesn't have anything in it.
How do I set the default text? Like for example if I have a insert
template field that is databound to a date sql column how can I set the
text to be a default like todays date?

Jan 31 '06 #1
4 3594
Use the ItemDataBound event. This event fires after the databinding occurs
for each Item, so it occurs the same number of times as the number of Items.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"MasterChie f" <co*******@mi x-net.net> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I have an insert template textbox that is bound to a field in SQL.
Since it is the insert template it really doesn't have anything in it.
How do I set the default text? Like for example if I have a insert
template field that is databound to a date sql column how can I set the
text to be a default like todays date?

Feb 1 '06 #2
I can't seem to find the ItemDataBound event. I can find it for the
gridview but not the formview which is where the insert template I am
using is. I am trying to use the databinding event is that the same
thing as ItemDataBound? Also how do I reference the textbox in the form
view? Like I can't see to go plan_startdateT extBox.text =
DateTime.Today. ToString()

Protected Sub plan_startdateT extBox_DataBind ing(ByVal sender As
Object, ByVal e As System.EventArg s)

End Sub

Feb 2 '06 #3
I searched for hours and finally came upon this posting if anybody is
interested.
http://groups.google.com/group/micro...e822433a4ab209

Feb 2 '06 #4
Here is an example from code that I wrote:
Private Sub datResults_Item DataBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data ListItemEventAr gs) Handles
datResults.Item DataBound

If e.Item.ItemType = ListItemType.It em AndAlso
CType(e.Item.Fi ndControl("lblR egion1"), Label).Text = "*NONE*" Then

CType(e.Item.Fi ndControl("lblR egion1"), Label).Text = "&nbsp;"

End If

If e.Item.ItemType = ListItemType.Al ternatingItem AndAlso
CType(e.Item.Fi ndControl("lblR egion2"), Label).Text = "*NONE*" Then

CType(e.Item.Fi ndControl("lblR egion2"), Label).Text = "&nbsp;"

End If

If e.Item.ItemType = ListItemType.It em AndAlso
CType(e.Item.Fi ndControl("lblP hone1"), Label).Text = "" Then
CType(e.Item.Fi ndControl("lblP hone1"), Label).Text = "&nbsp;"

If e.Item.ItemType = ListItemType.Al ternatingItem AndAlso
CType(e.Item.Fi ndControl("lblP hone2"), Label).Text = "" Then
CType(e.Item.Fi ndControl("lblP hone2"), Label).Text = "&nbsp;"

End Sub

Notice that at the end of the first line it refers to the event as
datResults.Item DataBound (this is the standard objectID.eventn ame format).
As for your question about referencing a textbox (or any other Control used
in your Template), you must use
CType(e.Item.Fi ndControl(contr olID),ControlTy pe) to reference the Control.
This is necessary because since there are many Items in a DataList (for
example, my example will include many controls with the ID lblPhone1), you
cannot simply use just the ID. All my sample code is in VB.NET, if you have
any questions let me know.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"MasterChie f" <co*******@mi x-net.net> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
I can't seem to find the ItemDataBound event. I can find it for the
gridview but not the formview which is where the insert template I am
using is. I am trying to use the databinding event is that the same
thing as ItemDataBound? Also how do I reference the textbox in the form
view? Like I can't see to go plan_startdateT extBox.text =
DateTime.Today. ToString()

Protected Sub plan_startdateT extBox_DataBind ing(ByVal sender As
Object, ByVal e As System.EventArg s)

End Sub

Feb 3 '06 #5

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

Similar topics

3
2327
by: Ben R. | last post by:
I've got a repeater that's bound to a datareader and I'd like to conditionally modify the text that is being outputted. Previously, I've done this by assigning a name to attribute to the surrounding tablecell in which the <%# %> tags reside and I could use the findcontrol to grab a handle to the control by name and do any necessary...
1
9531
by: Patrick Demets | last post by:
I have a fairly simple form with databound text boxes, but changes (or new records) are not recognized. The text boxes are successfully populated with data (from the database) and I can cycle through all the records. Using a datagrid works fine for updating. I've based this on the first sample project from the book "C# Professional...
4
2299
by: Harold | last post by:
I have read the following article http://www.4guysfromrolla.com/webtech/073101-1.shtml. I added the empty selection as the first option. When I click submit without choosing anything it does not return my empty string but the 2nd value in listbox. When the page reloads it selects the 2nd option by default even thou my Empty field is in the...
2
1122
by: Vayse | last post by:
I have an access table Vehicles. There is a field Purchase Price, which has a default value of zero. In my databound form, I didn't include the purchase price. Now when I save, the PurchasePrice is null. Likewise for other fields that were not on the form. How do I prevent vb.net from over writing the default values? Thanks Vayes
1
2860
by: IMB | last post by:
I'm using VS2005 and am working with a ASP.NET 2.0 web site and I'm coding in VB.NET. I understand that I can add an item to a databound dropdownlist and make it the default selection using the following code: MyDropDownList.Items.Insert(0, "My default item") MyDropDownList.SelectedIndex = 0 The problem that I am experiencing is...
1
1287
by: sck10 | last post by:
Hello, I am inserting the values for radio buttons on a form into a database. There are 25 questions with 4 possible answers (see below). Is it possible to pragmatically build the radio button name so I can loop through the possibilities? For example I would like to be able to build the rbn in a loop for:
6
5670
by: David Veeneman | last post by:
I am looking for a resource to learn how to do multithreading in a data bound app. So far, I have figured out that I can't update a databound object on a worker thread, because that triggers a cross-thread call to the UI control that it is bound to. I have created a simple demo to explore the problem. The demo has a dataGridView control, a...
3
1241
by: Steve | last post by:
I have a databound dropdown in my page. I want to make one of the values the default value. Any ideas? Just to explain further, I have also appended one item to the dropdown, using the AppendDataBoundItems="True" property of the dropdown. Unfortunately the item I have appended to the dropdown has become the default value of the dropdown...
5
26622
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 the data from a single objectdatasource. All textboxes and ddl(s) support null values. Textboxes are for entering numbers and ddl(s) are for selecting...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.