Solved

Get the detailsview value

Posted on 2007-04-04
6
1,233 Views
Last Modified: 2008-01-09
A column in my detailsview contains an id, i'd like to use this id as part of a link on the page.
I've been messing about with a label trying to get this value but am falling short...
code behind
label1.text = detailsview. ???????
0
Comment
Question by:QPR
  • 4
6 Comments
 
LVL 4

Accepted Solution

by:
vitjan earned 300 total points
ID: 18853927
Hi QPR,

I am just guessing what you really need.
Would this work for you:
label1.text = DetailsView1.Rows[0].Cells[0].Text

Regards,
Jan

0
 
LVL 29

Author Comment

by:QPR
ID: 18854217
"detailsview collection cannot be converted to type string"
0
 
LVL 29

Author Comment

by:QPR
ID: 18854616
I think the [0] should be (0) ?
This way I don't get "squiggles"

However when I use it I now get
System.ArgumentOutOfRangeException was unhandled by user code
  Message="Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
  ParamName="index"
  Source="mscorlib"
 
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Assisted Solution

by:mzalewski
mzalewski earned 200 total points
ID: 18854643
Is this code being executed after the data is bound to the detailsview?
vitjan posted C# code, you must be using VB.NET?

"Index was out of range" tells me that either the Rows or Cells Collection is empty. This could be because you have placed this code before any databinding code.

You can check the count of the collections like this
if (DetailsView1.Rows.Count > 0 && DetailsView1.Rows[0].Cells.Count > 0)
0
 
LVL 29

Author Comment

by:QPR
ID: 18854663
I have no "code behind" other than what I am trying to do with the lable.
When is a detailsview databound?
Which event should I use to make sure that I only try to populate the label when the detailsview is populated?
 <asp:DetailsView ID="DetailsView1" runat="server" BackColor="#DEBA84"
            BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
            DataSourceID="SqlDataSource1" Height="50px" Width="488px" AutoGenerateRows="False" DataKeyNames="propno">
0
 
LVL 29

Author Comment

by:QPR
ID: 18854709
Solved, the problem was that when I launched from VS2005 there was no querystring data.
This data was needed to populate the detailsview.
I changed the start page when launching and by navigating to the page in question (with querystring data) I was able to get it to work.

And yes vb.net not C# - sorry I should have specified.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 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

13 Experts available now in Live!

Get 1:1 Help Now