C# 让中继器内的复选框将数据从中继器内的文本框发送到中继器外的另一个文本框

C# 让中继器内的复选框将数据从中继器内的文本框发送到中继器外的另一个文本框,c#,asp.net,repeater,C#,Asp.net,Repeater,我有一个中继器,它填充一个由3列组成的列表,每行旁边都有一个复选框。我正在尝试创建一个场景,在该场景中,一个人检查一行,页面会在repeaters行中找到部分名称文本框,该行对应于已单击复选框的行,选中该复选框后,它会将部分名称发送到repeater外的另一个文本框testTextBox.text。下面是我的代码,我确信我遗漏了一些东西,因为我以前没有做过OnCheckChanged事件,我只熟悉onTextChanged事件 代码如下: <asp:Repeater ID="rptAcco

我有一个中继器,它填充一个由3列组成的列表,每行旁边都有一个复选框。我正在尝试创建一个场景,在该场景中,一个人检查一行,页面会在repeaters行中找到部分名称文本框,该行对应于已单击复选框的行,选中该复选框后,它会将部分名称发送到repeater外的另一个文本框testTextBox.text。下面是我的代码,我确信我遗漏了一些东西,因为我以前没有做过OnCheckChanged事件,我只熟悉onTextChanged事件

代码如下:

<asp:Repeater ID="rptAccount" runat="server" OnItemCommand="rptAccount_ItemCommand">
             <HeaderTemplate>
                            <table>
                                <tr>
                                    <th>Account
                                    </th>
                                    <th>Portion ID
                                    </th>
                                    <th>Portion Name
                                    </th>                                                                                                
                                </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                   <asp:TextBox ID="Account"  runat="server" Width ="50px" Text='<%#Eval("Account") %>' ></asp:TextBox>
                                </td>
                                <td>
                                   <asp:TextBox ID="PortionID"  runat="server" Width ="90px" Text='<%#Eval("Portion ID") %>' ></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="PortionName" runat="server" Width ="340px" Text='<%#Eval("Portion Name") %>'></asp:TextBox>
                                </td>    
                                <td>
                                    <asp:CheckBox ID="Name" runat="server" OnCheckedChanged = "TbName_CheckedChanged" Checked='<%# Eval("Name").ToString() == "True" %>' ></asp:CheckBox>
                                    </td>                                                                            
                               </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>     
        </asp:Repeater>

谢谢你能提供的任何帮助

中继器最终拥有大量名为的控件。请记住,模板会重复多次。您需要找到当前项的索引。一种更简单的方法是将属性附加到复选框以保存文本值,这样您就可以直接从发送方提取文本值,而不必担心父项和索引。试试这个:

<asp:Repeater ID="rptAccount" runat="server" OnItemCommand="rptAccount_ItemCommand">
             <HeaderTemplate>
                            <table>
                                <tr>
                                    <th>Account
                                    </th>
                                    <th>Portion ID
                                    </th>
                                    <th>Portion Name
                                    </th>                                                                                                
                                </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                   <asp:TextBox ID="Account"  runat="server" Width ="50px" Text='<%#Eval("Account") %>' ></asp:TextBox>
                                </td>
                                <td>
                                   <asp:TextBox ID="PortionID"  runat="server" Width ="90px" Text='<%#Eval("Portion ID") %>' ></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="PortionName" runat="server" Width ="340px" Text='<%#Eval("Portion Name") %>'></asp:TextBox>
                                </td>    
                                <td>
                                    <asp:CheckBox ID="Name" runat="server" OnCheckedChanged = "TbName_CheckedChanged" CommandName='<%#Eval("Portion Name") %>' Checked='<%# Eval("Name").ToString() == "True" %>' ></asp:CheckBox>
                                    </td>                                                                            
                               </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>     
        </asp:Repeater>

您应该使用rptAccount_itemCommands,该命令将插入到aspx页面的什么位置?仍在OnCheckChanged事件下?可能重复
<asp:Repeater ID="rptAccount" runat="server" OnItemCommand="rptAccount_ItemCommand">
             <HeaderTemplate>
                            <table>
                                <tr>
                                    <th>Account
                                    </th>
                                    <th>Portion ID
                                    </th>
                                    <th>Portion Name
                                    </th>                                                                                                
                                </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                   <asp:TextBox ID="Account"  runat="server" Width ="50px" Text='<%#Eval("Account") %>' ></asp:TextBox>
                                </td>
                                <td>
                                   <asp:TextBox ID="PortionID"  runat="server" Width ="90px" Text='<%#Eval("Portion ID") %>' ></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="PortionName" runat="server" Width ="340px" Text='<%#Eval("Portion Name") %>'></asp:TextBox>
                                </td>    
                                <td>
                                    <asp:CheckBox ID="Name" runat="server" OnCheckedChanged = "TbName_CheckedChanged" CommandName='<%#Eval("Portion Name") %>' Checked='<%# Eval("Name").ToString() == "True" %>' ></asp:CheckBox>
                                    </td>                                                                            
                               </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>     
        </asp:Repeater>
protected void TbName_CheckedChanged(object sender, EventArgs e)
    {   
        var checkedd = sender as Checkbox;     

        if (checkedd.Checked)
            testTextBox.Text = checkedd.Attributes["CommandName"];
    }