2016-11-13 4 views
0
私はボタンをクリックリピータテーブルで選択した行を印刷したい

を使用して行をチェックし、これが.aspxのコードです:ASP:C#の印刷]チェックボックス

<asp:Repeater ID="rptItems" runat="server"> 
     <HeaderTemplate> 
      <table class="table table-bordered table-hover table-responsive table-striped table-condensed"> 

       <tr> 
        <th> </th> 
        <th>Goods Desc</th> 
        <th>Balance Units</th> 
        <th>Exit Units</th> 
       </tr> 
     </HeaderTemplate> 

     <ItemTemplate> 
      <tr> 
       <td><asp:CheckBox ID="cbItem" runat="server" ClientIDMode="AutoID" AutoPostBack="True" /></td> 

       <td><asp:Label runat="server" Id="lblCampCode" Text='<%#Eval("ItemDesc") %>'></asp:Label></td> 

       <td><asp:Label ID="lblBalUnits" runat="server" text='<%#Eval("InvoicBalanceUnits") %>'></asp:Label> </td> 

       <td><asp:TextBox ID="txtExitUnits" runat="server"></asp:TextBox> 
        <asp:RegularExpressionValidator ID="revUnits" runat="server" Display="Dynamic" ControlToValidate="txtExitUnits" ValidationExpression="^\d+$" ErrorMessage="Please, insert a number." CssClass="text-danger"></asp:RegularExpressionValidator> 
        <asp:RequiredFieldValidator ID="rfvUnits" runat="server" Display="Dynamic" ControlToValidate="txtExitUnits" ErrorMessage="Insert number of units." CssClass="text-danger"></asp:RequiredFieldValidator> 
         </td> 


      </tr> 



     </ItemTemplate> 


     <FooterTemplate> 
       </table> 
     </FooterTemplate> 



    </asp:Repeater> 


    <asp:Button ID="btnExit" runat="server" Text="Exit now" OnClick="btnExit_Click" /> 

、これはボタンのは.csコードですリピーターで、これまで確認された項目のためにループするイベントをクリックして、チェックした行データを取得します:

protected void btnExit_Click(object sender, EventArgs e) 
    { 
     foreach (RepeaterItem item in rptItems.Items) 
     { 
      if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) 
      { 
       CheckBox checkBoxInRepeater = item.FindControl("cbItem") as CheckBox; 

       if (checkBoxInRepeater.Checked) 
       { 
        Label lblCampCode = (Label)item.FindControl("lblCampCode"); 
        Label lblBalUnits = (Label)item.FindControl("lblBalUnits"); 
        TextBox txtExitUnits = (TextBox)item.FindControl("txtExitUnits"); 
        string CampCode = lblCampCode.Text; 
        string BalUnits = lblBalUnits.Text; 
        string ExitUni = txtExitUnits.Text; 

       } 
      } 
     } 

    } 

私は、データを格納するデータテーブルを使用すべきだと思います。

+0

ボタンをクリックしますか? –

答えて

0

私はこのようなデータテーブルを使用することによってそれを解決:その後、私は、データソースとして、ユーザは自分が欲しいものをチェックするたびに3 CampCode、BalUnits、ExitUni文字列を渡します、私は新しいリピーターを作りたい

DataTable checkedData = new DataTable(); 
     checkedData.Columns.AddRange(new DataColumn[6] { new DataColumn("CampCode"), new DataColumn("BalUnits", typeof(decimal)), new DataColumn("ExitUni",typeof(decimal)), new DataColumn("itemNum"), new DataColumn("UOM"), new DataColumn("WT", typeof(decimal)) }); 

dr["CampCode"]=lblexitUnits.text; 
//And so on 
DataRow dr = checkedData.NewRow();