Fares Ayyad

Fares Ayyad

  • NA
  • 235
  • 74.3k

asp/c# print only selected items using checkbox?

Nov 13 2016 5:56 AM

I have a repeater shows items with checkbox for each item, i have a button that will print only the selected rows, but how to save the checked rows as a datatable or something like that:

 
this is the .aspx :
 
  1. <tr>  
  2.                 <td><asp:CheckBox ID="cbItem" runat="server"  ClientIDMode="AutoID" AutoPostBack="True" /></td>  
  3.                   
  4.                 <td><asp:Label runat="server" Id="lblCampCode" Text='<%#Eval("ItemDesc") %>'></asp:Label></td>  
  5.   
  6.                 <td><asp:Label ID="lblBalUnits" runat="server" text='<%#Eval("InvoicBalanceUnits") %>'></asp:Label> </td>  
  7.   
  8.                 <td><asp:TextBox ID="txtExitUnits" runat="server"></asp:TextBox>  
  9.                     <asp:RegularExpressionValidator ID="revUnits" runat="server" Display="Dynamic" ControlToValidate="txtExitUnits" ValidationExpression="^\d+$" ErrorMessage="Please, insert a number." CssClass="text-danger"></asp:RegularExpressionValidator>  
  10.                     <asp:RequiredFieldValidator ID="rfvUnits" runat="server" Display="Dynamic" ControlToValidate="txtExitUnits" ErrorMessage="Insert number of units." CssClass="text-danger"></asp:RequiredFieldValidator>  
  11.                       </td>  
  12.            
  13.   
  14.             </tr>  
 and this is the button event :
 
  1. protected void btnExit_Click(object sender, EventArgs e)  
  2. {  
  3.     foreach (RepeaterItem item in rptItems.Items)  
  4.     {  
  5.         if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)  
  6.         {  
  7.             CheckBox checkBoxInRepeater = item.FindControl("cbItem"as CheckBox;  
  8.   
  9.             if (checkBoxInRepeater.Checked)  
  10.             {  
  11.                 Label lblCampCode = (Label)item.FindControl("lblCampCode");  
  12.                 Label lblBalUnits = (Label)item.FindControl("lblBalUnits");  
  13.                 TextBox txtExitUnits = (TextBox)item.FindControl("txtExitUnits");  
  14.                 string CampCode = lblCampCode.Text;  
  15.                 string BalUnits = lblBalUnits.Text;  
  16.                 string ExitUni = txtExitUnits.Text;  
  17.                   
  18.             }  
  19.         }  
  20.     }  
  21.   
  22. }  
 i want to save the CampCode,BalUnits,ExitUni, for each row checked ?
 
 
 

Answers (2)