473,406 Members | 2,259 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,406 software developers and data experts.

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 3585
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********@hotmail.com
http://www.nathansokalski.com/

"MasterChief" <co*******@mix-net.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.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_startdateTextBox.text =
DateTime.Today.ToString()

Protected Sub plan_startdateTextBox_DataBinding(ByVal sender As
Object, ByVal e As System.EventArgs)

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_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
datResults.ItemDataBound

If e.Item.ItemType = ListItemType.Item AndAlso
CType(e.Item.FindControl("lblRegion1"), Label).Text = "*NONE*" Then

CType(e.Item.FindControl("lblRegion1"), Label).Text = "&nbsp;"

End If

If e.Item.ItemType = ListItemType.AlternatingItem AndAlso
CType(e.Item.FindControl("lblRegion2"), Label).Text = "*NONE*" Then

CType(e.Item.FindControl("lblRegion2"), Label).Text = "&nbsp;"

End If

If e.Item.ItemType = ListItemType.Item AndAlso
CType(e.Item.FindControl("lblPhone1"), Label).Text = "" Then
CType(e.Item.FindControl("lblPhone1"), Label).Text = "&nbsp;"

If e.Item.ItemType = ListItemType.AlternatingItem AndAlso
CType(e.Item.FindControl("lblPhone2"), Label).Text = "" Then
CType(e.Item.FindControl("lblPhone2"), Label).Text = "&nbsp;"

End Sub

Notice that at the end of the first line it refers to the event as
datResults.ItemDataBound (this is the standard objectID.eventname format).
As for your question about referencing a textbox (or any other Control used
in your Template), you must use
CType(e.Item.FindControl(controlID),ControlType) 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********@hotmail.com
http://www.nathansokalski.com/

"MasterChief" <co*******@mix-net.net> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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_startdateTextBox.text =
DateTime.Today.ToString()

Protected Sub plan_startdateTextBox_DataBinding(ByVal sender As
Object, ByVal e As System.EventArgs)

End Sub

Feb 3 '06 #5

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

Similar topics

3
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...
1
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...
4
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...
2
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...
1
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...
1
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...
6
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...
3
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.