Retrieving Data in Code
I want to create a mail service that (1) looks up a recommended subject heading in a database and (2) inserts that heading on the screen’s form. The sender is free to keep that heading or change it.
When the service sends the email, it takes the subject from the subject textbox and uses that as the mail object’s subject property.
The problem is that I cannot get the server to recognize the name of the subject box.
I have named the subject text box “tbSubject”; however, when I try to use that name in code I get an exception stating that tbSubject is undeclared. Of course, it has been declared, but it is part of a datalist.
I have tried to use the datalist name as in: dlSubject.tbSubject.Text or dlSubject.ItemTemplate.tbSubject.Text.
That doesn’t work either. Surely there is some simple way to refer to the text in a textbox that contains bound data.
jsheplerPosted Oct 6, 2004, 3:16 PM
... TextBox tb; foreach(DataListItem item in dlSubject.Items) { tb = item.FindControl("tbSubject"); ... } ...This would iterate through each row in the datalist and give you a reference to the tbSubject control in each row. It sounds like your datalist only has 1 row. If this is the case, why are you using a datalist containing a textbox instead of just a textbox that can be referenced normally?