1
Answer

Retrieving Data values from ListView

Carmen

Carmen

15y
5.4k
1

This is my ListView
<
asp:ListView ID="ListView1" runat="server" >
<LayoutTemplate>
<table runat="server" id="itemTable">
<tr>
<th></th>
<th>Name 1</th>
<th>Name 2</th>
<th>Name 3</th>
<th>Name 4</th>
<th>Name 5</th>
</tr>
<tr runat="server" id="itemPlaceholder" ></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><asp:CheckBox ID="CheckBox1" runat="server" /></td>
<td><%# DataBinder.Eval(Container.DataItem, "name1") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "name2") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "name3") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "name4") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "name5") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
This is My code
protected
void Button1_Click(object sender, EventArgs e)
{
      for (int i = 0; i < ListView1.Items.Count; i++)
      {
         CheckBox chk = ListView1.Items[i].FindControl("CheckBox1") as CheckBox;
         if(chk.Checked == true)
      {
         ** Here I want to be able to get the value of 
            <td><%# DataBinder.Eval(Container.DataItem, "name1") %></td>
         From my ListView ItemTemplate**
      }
   }
}
Answers (1)
0
Roei Bar

Roei Bar

NA 7.8k 0 15y

hey, i would recommend you to change your work, to work with CheckedListBox
you will have a CheckedItems Property in this, and the Value is the text in it, and if you want complex Object with multiple properties, you can have an object, and on the build just do an Override on the ToString for the displayed item Text and once you run all all Checked Items, you will have the ItemId, and by ItemId you can get any property in the ListView