Solved

access value of listview

Posted on 2014-01-27
10
314 Views
Last Modified: 2014-01-28
how can I access the value of a field of a list view control?

I am trying like this:

Dim myRecipeStepsHistory = myContext.RefineRecipeStep.Where("it.Recipe_Id=" & Me.lvRecipeSteps.FindControl("Recipe_Id").ToString())


But I get an error estating that Object needs to be instantiated.

Please any help would be great. Thank you.
0
Comment
Question by:metropia
[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
  • 7
  • 3
10 Comments
 

Author Comment

by:metropia
ID: 39814244
I also tried:

           Dim tb As TextBox = DirectCast(Me.lvRecipeSteps.FindControl("Recipe_Id"), TextBox)
            Dim x As String = tb.Text

but get:
Object reference not set to an instance of an object.

on line:
            Dim x As String = tb.Text

Any ideas?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39814773
You can find the item using listview.Items property and then use FindControl on this item to get the specific control value. Example here

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.items(v=vs.110).aspx
0
 

Author Comment

by:metropia
ID: 39815069
I tried your recommendation but I get a message: NewEditIndex is not a member of System.....

error
Can you see what I am missing?

Thank you very much.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 500 total points
ID: 39815498
Change that line to

Dim item As ListViewItem = e.Item
0
 

Author Comment

by:metropia
ID: 39815604
let me try that :)
0
 

Author Comment

by:metropia
ID: 39815615
that took the error away. how would I access a field on the listview after that?
when it is in update/ edit mode.

thank a lot.
0
 

Author Comment

by:metropia
ID: 39815627
I did this:

        If e.CommandName = "Update" Then
            Dim myContext As New OLTPEntities
            Dim item As ListViewItem = e.Item
            Dim tbx As TextBox = DirectCast(item.FindControl("Recipe_IdLabel"), TextBox)

Open in new window


But it tbx contains Nothing.

The field I am trying to access to when on Edit:

<td class="RefineRecipe_Steps_Cells"><asp:Label ID="Recipe_IdLabel" runat="server" Text='<%# Eval("Recipe_Id") %>' /></td>

Open in new window

0
 

Author Comment

by:metropia
ID: 39815769
this works:

            Dim item As ListViewItem = e.Item

            Dim tbx As TextBox = TryCast(item.FindControl("Recipe_IdTextBox"), TextBox)
            Dim strRecipeId As String = String.Empty

            strRecipeId = tbx.Text

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39816316
Cool. So problem sorted?
0
 

Author Comment

by:metropia
ID: 39816501
Somehow. I granted you the points because your comment helped me to fix the issue of this question. Unfortunately it also made me realized there were other errors needing fixing. Because of that I created another question I hope you can take a look to.

Thanks a lot. :)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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