Solved

Get the detailsview value

Posted on 2007-04-04
6
1,243 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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