Usual Databinding Question - UNusual Requirements

N

Neo Geshel

Greetings!

I have a rather unusual request about a rather basic need. I need to be
able to bind data to a page, but WITHOUT using a Repeater, DataGrid or
DataList.

Why?

Well, I have some formatting and JavaScript issues that require each and
every form element's ID to remain unchanged. Unfortunately, whenever
data binding occurs within a Repeater, DataList or DataGrid, the form
ID’s are changed to something different (i.e., there is additional stuff
appended to the ID name to allow ASP.NET to track it).

I know I can data bind a single item to a single form element by using
ExecuteScalar(). That is, the following works great if all I want is to
bind the contents of a single database field to a single form element:

Sub EditIntro()
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("SELECT [Comment] FROM [tblIntro]", myConn)
myConn.Open()
ltrlIntro.Text = FormatData(myCmd.ExecuteScalar())
IntroComment.Text = myCmd.ExecuteScalar()
myConn.Close()
End Sub

In this example, a single database field (for which only one entry, or
row, exists) is bound to both a literal (providing an excellent preview
of the database field’s contents) as well as a form <textarea> (so that
the current contents of the database field can be displayed and any
changes updated).

However, I need to be able to bind multiple database fields of just a
single database entry (or row) to multiple literals and multiple form
fields. Since I will be calling up just one database entry, I do not
want to use a Repeater, DataList or DataGrid, since these are best used
for displaying multiple database entries and will muck up the ID’s that
are used by the form fields.

Are there any online resources that I can be pointed to? Or does anyone
have any ideas?

PS, I would like any solution, if possible, to be applicable to both
ASP.NET 1.1 as well as ASP.NET 2.0. I am building an XHTML 1.1 + CSS 2.1
compliant web app, so I need flexibility.

TIA
...Geshel
--
***********************************************************************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
***********************************************************************
“Anyone who believes in Intelligent Design (“creationismâ€) is just as
ignorant and ill-educated as someone who believes that the world is
flat, that the Sun circles the Earth or that there really is a tooth
fairy. Darwinism has an overwhelming foundation of evidence that can be
tested and reproduced. Intelligent Design, on the other hand, has no
evidence at all; not one single shred of testable proof. As such,
Intelligent Design is Religious Mythology, and has no right whatsoever
to be in our Science classrooms.†- 99.99+% of Scientists
***********************************************************************
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.†Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
***********************************************************************
 
T

Tapio Kulmala

try this:


Sub EditIntro()
Dim myConn as
New OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("SELECT [Comment] FROM [tblIntro]",
myConn)
myConn.Open()

Dim rdr As OleDbDataReader
rdr = myCmd.ExecuteReader()
rdr.Read()

ltrlIntro.Text = FormatData(rdr("Comment"))
IntroComment.Text = rdr("Comment")

myConn.Close()
End Sub


Now you can add more columns into your select-statement and use use them
in your program any way you want.



--
****************************************************************
Tapio Kulmala

"Those are my principles. If you don't like them I have others."

- Groucho Marx
****************************************************************
 
F

Flinky Wisty Pomm

I'm the awkward type, so I might try and fix the other problem: your
dependency on an ID. I use classes over unique IDs for CSS, and I've
got a quick and dirty JScript function that takes an id and a tagname
and searches for matching elements, returning the first match.

Is there a similar workaround in your case?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DataBinding expressions with multiple fields 2
Unusual Error Catching Behaviour 0
DataBinding 0
An unusual use of case/switch 55
A simple form question 2
An unusual question... 2
Complex databinding 1
DataBinding 1

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top