Fares Ayyad

Fares Ayyad

  • NA
  • 235
  • 74k

Asp.net/C# Get repeater row data through checkbox

Nov 10 2016 7:58 AM
 
Hello i have a repeater that will present data as a table with checkbox for each row, so i want to show the checked rows data when a button is clicked.
 
.aspx code:
 
  1. "rptItems" runat="server">  
  2.          
  3.            class="table table-bordered table-hover table-responsive table-striped table-condensed">  
  4.   
  5.                  
  6.                       
  7.                    Goods Desc  
  8.                    Balance Units  
  9.                    Exit Units  
  10.                  
  11.          
  12.   
  13.          
  14.              
  15.                "cbItem" runat="server" />  
  16.   
  17.                <%#Eval("ItemDesc") %>  
  18.                <%#Eval("InvoicBalanceUnits") %>  
  19.                "txtExitUnits" runat="server" >  
  20.                    "revUnits" runat="server" Display="Dynamic" ControlToValidate="txtExitUnits" ValidationExpression="^\d+$" ErrorMessage="Please, insert a number." CssClass="text-danger">  
  21.                    "rfvUnits" runat="server" Display="Dynamic" ControlToValidate="txtExitUnits" ErrorMessage="Insert number of units." CssClass="text-danger">  
  22.                        
  23.   
  24.   
  25.              
  26.   
  27.   
  28.   
  29.          
  30.   
  31.   
  32.          
  33.                   
  34.          
  35.   
  36.   
  37.   
  38.      
 
the code behind:
  1. protected void btnExit_Click(object sender, EventArgs e)  
  2.    {  
  3.   
  4.        List selectedItems = rptItems.Items.Cast().Where(x => ((CheckBox)x.FindControl("cbItem")).Checked).ToList();  
  5.   
  6. epeater1.DataSource = selectedItems;  
  7.        Repeater1.DataBind();  
 
 Repeater1 will contain the data selected through :selectedItems this is the repeater1
 
  1. "Repeater1" runat="server">  
  2.       
  3.         class="table table-bordered table-hover table-responsive table-striped table-condensed">  
  4.   
  5.               
  6.   
  7.                 Goods Desc  
  8.                 Balance Units  
  9.   
  10.               
  11.       
  12.   
  13.       
  14.           
  15.   
  16.   
  17.             <%#Eval("ItemDesc") %>  
  18.             <%#Eval("InvoicBalanceUnits") %>  
  19.   
  20.   
  21.   
  22.           
  23.   
  24.   
  25.   
  26.       
  27.   
  28.   
  29.       
  30.                
  31.       
  32.   
  33.   
  34.   
  35.   
 when i run the code it gives me an error that "ItemDesc" isn't exist in repeater1, whats wrong ?
 

Answers (2)