Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all .
I coudn't understand how i can acess item in listview programmatically . I have textbox in my listview:
ASP.NET
  <asp:ListView ID="ListView1" ... EnableViewState="false" 
        runat="server"  >
... <EditItemTemplate>
            <tr> ...

 <td>
                    <asp:TextBox runat="server"  OnTextChanged="Commenary_TextChanged"   id="Commenary"/></td>
                     <td>


I need to take text from textbox and save it in string variable . How i can make it?

What I have tried:

I try to find it in my listview like this :

C#
var item = ListView1.FindControl("Commentary");
string asd = item.ToString();


And like this:
C#
TextBox tmpControl = (TextBox)ListView1.FindControl("Commentary");
string  xxx = tmpControl.Text.ToString();


I have null in both situarion.
Also i tried to change textbox to input tag, but i have nothing too.
Posted
Updated 9-Jun-16 6:11am
v2

1 solution

There is an example of how to edit a listview and access the controls here

Edit,Update,Delete and Insert in ListView Control[^]
 
Share this answer
 
Comments
Андрей Голубцов 10-Jun-16 3:57am    
Thanks, it works! . In my situation it is
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
TextBox txt = (ListView1.Items[e.ItemIndex].FindControl("Commenary")) as TextBox;
comment = txt.Text.ToString();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900