Solved

access value of listview

Posted on 2014-01-27
10
310 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
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.…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

816 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

10 Experts available now in Live!

Get 1:1 Help Now