473,394 Members | 1,748 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,394 software developers and data experts.

How do I access the text inside a TemplateField within DetailsView?

I am using a DetailsView to display some data. I am basically getting a firstname, and lastname fields from a database (the database cannot be changed, nor the queries), and I must concatenate the [lastname], [firstname]. I want to incorporate this into a detailsview like so...

Expand|Select|Wrap|Line Numbers
  1.  <asp:TemplateField HeaderText="Name:">
  2.     <ItemTemplate>
  3.         <%#Eval("firstname")%>, <%#Eval("lastname")%>
  4.     </ItemTemplate>                           
  5. </asp:TemplateField>
I am doing this because I need the detailsview to make the row not visible if there is no data present in the field. So I have an event like so...(this event is located in a class which extends the detailsview control)


Expand|Select|Wrap|Line Numbers
  1.         Protected Overrides Sub OnDataBound(ByVal e As System.EventArgs)
  2.             Dim row As DetailsViewRow
  3.             For Each row In Me.Rows
  4.                 If String.IsNullOrEmpty(row.Cells(1).Text) Or row.Cells(1).Text = "&nbsp;" Then
  5.                     row.Visible = False
  6.                 End If
  7.             Next
  8.         End Sub
  9.  
When the row being tested is the templatefield row shown above, the value (row.Cells(1).Text) returns an empty string, yet all boundfields return their values fine, and it works as expected. Also if I take the event out, the data returns fine! It just doesn't seem to be available in the life-cycle at the time of the databound event, which is extremely strange.

I do not want to add a control inside the itemtemplate, I tried that and it worked, but is there anyway to access the data inside the templatefield for how it is shown? I posted this on Asp.net forums if you would like to take a look there too.

http://forums.asp.net/t/1203270.aspx

Apparently, it must bind the Eval() statments at a later time...

Thanks!
Jan 10 '08 #1
1 2164
anyone? I need to know this badly!
Jan 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Frits van Soldt | last post by:
Hello, I hope somebody can help me with this! I have 2 listboxes in the edititemtemplate of a detailsview. In the databound event of the detailsview I would like to fill the listboxes...
5
by: clickon | last post by:
This is driving me nuts, it is such a simply thing to do but i cannot for the life of me work out how you are suposed to do it. I want to update the data in DropDownListB based on what is...
1
by: odd.morten.sveas | last post by:
Hi I'm building a web site where some users can create receivables (invoices). This website will support several organisations and different users migth have responibility for more that one...
0
by: Cas | last post by:
Hi, I want to create a InsertItemTemplate in a detailsview (only insertmode)programmatically. I first defined a Template, then i tried to create within that templatefield a InsertItemTemplate...
0
by: Christian Schlemmer | last post by:
hi, in a DetailsView i have a image display. images i want to store in a seperate directory, but it a path is added to Bind update and delete is not working. just Bind makes my...
2
by: Bazza Formez | last post by:
I have a bound field in a DetailsView control that displays free form description type data from my SQL database table (typical data is a couple of paragraphs of written product description being...
1
by: Lazy Man | last post by:
Hi, custom DetailsView or Table with controls? For various reasons, I need to generate the edit controls in a DetailsView programmatically. I already do this to display an item, so Item mode...
1
by: gsauns | last post by:
I have a DetailsView inside a ModalPopup (using the AJAX ModalPopupExtender). I would like the user to have the ability to change the DetailsView's mode within the ModalPopup. But whenever I...
1
by: Eric | last post by:
Hi, I have a detailsview which shows large text. What i want is to show only the beginning of the text in normal mode and the full text in edit mode. Here the code: Thanks Eric ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.