Solved

Retrieving values from DetailsView Control with template fields

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

22 Experts available now in Live!

Get 1:1 Help Now