Solved

Retrieving values from DetailsView Control with template fields

Posted on 2007-11-13
4
1,621 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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