Solved

Retrieving values from DetailsView Control with template fields

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now