Solved

Get the detailsview value

Posted on 2007-04-04
6
1,241 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…

860 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