Skip to content

How to get data from listview in asp.net

mahnaz af

Asked Jun 4, 2015, 10:19 PM EDT11 answers
Share
LinkedInX
hi.i am trying to get values of listview in codebehind,but i dont know how do this.please help me.
 
GroupItemCount="3">





>


...??????? ?????
 
 
 
 i use this code:
TextBox countText = (TextBox)item .FindControl("txtcount"); 
but program error that:
 
Compiler Error Message: CS0103: The name 'item' does not exist in the current context

Source Error:

 
Code
Line 40:  Line 41:  Line 42:             TextBox countText = (TextBox)item .FindControl("txtcount");
 

11 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Najjaf Shuja
    +1
    Try this,
     
    TextBox countText = (TextBox)ListView1.Items[index].FindControl("txtcount");
    +1
  • Sathish Kumar
    +1
    Hi,
     
       You should use the eventsArgs object of that particular event,. Yu need to give it like,
     
          Textbox countTxt=(Textbox)e.Items.FindControl("txtCount"); 
    +1
  • Najjaf Shuja
    +1
    Can You show your code block in which you are getting textbox.. it will give clear idea what you are trying to do and in which method or event..
    +1
  • Najjaf Shuja
    +1
    its not a loop index. it is the index in listview having n items.
     
    TextBox countTxt = (ListView1.Items[0].FindControl("txtcount")) as TextBox;
    +1
  • Najjaf Shuja
    +1
    Because you are not mentioning from which index to find textbox
    +1
  • 0
    thanks for guide  but program does not recognize "items".!!!
    0
  • 0
    <asp:TextBox ID="txtcount" type="text" runat="server" Width="30"></asp:TextBox>
     
     
     
    in code  :TextBox countText = (TextBox)ListView1.Items[index].FindControl("txtcount");
     
    what 's "index" ?i have not any loop to use index.
    just  i want user enter text in textbox and i recieve text and use it.  
    0
  • 0
    this code work for one cells of listview.i have many cell in listview and i can't create manually
     index for them.
    why program not recognize the "item" to use this code: 
    Textbox countTxt=(Textbox)e.Items.FindControl("txtCount");
    0
  • 0
    i use from this code:
    TextBox CountText = (TextBox)this.ListView1.FindControl("txtcount");
    but  why this code return null??. 
    0
  • 0
    what to do that program recognize "items" to use this code:
    Textbox countTxt=(Textbox)e.Items.FindControl("txtCount");
    please help me 
    0
  • 0
    i understood that i use handler (ListViewItemEventArgs e).
    i want when click on button recieve value textbox  but handler (ListViewItemEventArgs e) don't work in 
    protected void addtobasket_Click(object sender, ListViewItemEventArgs e) ;
    how use handler (ListViewItemEventArgs e) in function protected void addtobasket_Click()??
    0