Solved

Retrieving values from DetailsView Control with template fields

Posted on 2007-11-13
4
1,617 Views
Last Modified: 2012-06-22
Hello Experts,

I'm new to the details view control.  I've created one, and and it's pulling data perfectly.  I then created an "accept" button.  When the user clicks it, take the first 2 fields of the DetailsView control and populate text boxes with them like this:

        txtCompanyName.Text = dvCompany.Rows(0).Cells(1).Text
        txtCompanyID.Text = dvCompany.Rows(1).Cells(1).Text

This was working like a charm.  Them I turned those first 2 fields into Template Fields so I could validate them.  Ever since then, the above lines pull a blank string.  It's almost like, the above just doesn't apply to template fields.  Or something.  Does anyone know how I can get this working?

Thanks,
GRCHELPDESK
0
Comment
Question by:GRCHELPDESK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20276445
If your template fields have controls within them, you will need to get the control value not the column value.

You can do it like this

Dim lblId As Label = CType(e.Item.FindControl("lblId"), Label)

that is for a label control with an id of lblId.

This needs to be used inside a grid event, otherwise e will not be found
0
 
LVL 2

Author Comment

by:GRCHELPDESK
ID: 20276507
Hey RedKelvin,

Thanks for the reply.  Although, I'm not following entirely.  I'm not sure what you mean about "inside the grid event".  Can you clarify that for me?  And also, will it be possible to have this happen in the button click event?

Thanks!
GRCHELPDESK
0
 
LVL 22

Accepted Solution

by:
RedKelvin earned 500 total points
ID: 20276791
Hi,
Yeah grid events, these are the events that fire as a result of things happening to the grid, updates, deletes etc.

If you want to do it from a button click, take a look at this thread, this is a question that I answered yesterday
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22956128.html

It is C#, the vb equiv, would look like this

    Dim textBoxText As TextBox

    For Each row As GridViewRow In GridView1.Rows
      textBoxText = CType(row.FindControl("TextBox1"), TextBox)
    Next
0
 
LVL 2

Author Comment

by:GRCHELPDESK
ID: 20280838
Hey RedKelvin,

Awesome, it's working.  I had to modify it a slightly, so I'll post that code for anyone running into this.  On button click:

        Dim lblCompanyName As Label
        Dim lblCompanyID As Label

        For Each row As DetailsViewRow In dvCompany.Rows
            lblCompanyName = CType(row.FindControl("label1"), Label)
            lblCompanyID = CType(row.FindControl("label2"), Label)
            txtCompanyName.Text = lblCompanyName.Text
            txtCompanyID.Text = lblCompanyID.Text
        Next

Many thanks for that!!

Cheers,
GRCHELPDESK
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where does legacy ASP.NET initialize language? 2 100
Data organization issue 7 55
Create a Dropdown list with sub group 10 43
asp.net repeater 2 35
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question