Solved

access value of listview

Posted on 2014-01-27
10
307 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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.…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

21 Experts available now in Live!

Get 1:1 Help Now