473,857 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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
When the row being tested is the templatefield row shown above, the value (row.Cells(1).T ext) 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.


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

Jan 10 '08 #1
1 2187
2 New Member
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

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 programmatically (not through databinding). If I use detailsview.findcontrol(controlname) then an empty object is returned. How can I address these controls? Thank you for your time.
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 selected in DropDownListA. I am not trying to do anything fancy with AJAX, i am happy to use Post Backs. If it were two controls just on the page then i would simply specify a control parameter for the SelectCommand of the SQLDataSource control which...
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 organisation. My problem is when I'm buliding this receivables page. The receivable are entered through a asp.net DetailsView. The first thing a user will do i to choose organisation. This is done by adding a DropDownList in a
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 (but i don't know how), and finally a textbox. I did this: (Detailsview1 is defined in the .aspx file) Dim tfield As TemplateField
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 DetailsView updateable, but scripts and images would be nice to be seperated.
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 held in a single database field of type ntext). This description data typically has various simple control characters in it - ie. new line, carriage returns etc) to make the paragraph more readable. My problem is that these control characters...
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 is fine, and the snippet below does the work. But I've been struggling mightily to make edit mode work. So the first question is, should I customize a DetailsView control, or should I build a table and embed the appropriate TextBoxes etc?
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 click the button to change the mode, the ModalPopup closes itself. The NEXT time I open the ModalPopup, the mode has been changed. So the mode is changing... my problem is that I need the ModalPopup to stay visible. Also, the DetailsView is inside...
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 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 most users, this new feature is actually very convenient. If you want to control the update process,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.