Solved

Get the detailsview value

Posted on 2007-04-04
6
1,245 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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