【发布时间】:2017-09-29 18:04:53
【问题描述】:
我有一个中继器,它填充 3 列的列表,并且每行旁边都有一个复选框。我正在尝试创建一个场景,其中一个人检查一行,页面在中继器行内找到与单击复选框的行相对应的“部分名称”文本框,一旦选中该复选框,它将“部分名称”发送到中继器外部名为“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>
cs代码:
protected void TbName_CheckedChanged(object sender, EventArgs e)
{
var PortionName = (sender as TextBox).Parent;
var rptAccount = (sender as TextBox).Parent;
var checkedd = rptAccount.FindControl("Name") as CheckBox;
var PortionNamee = rptAccount.FindControl("PortionName") as TextBox;
if (checkedd.Checked)
{
testTextBox.Text = PortionNamee.Text;
}
}
感谢您提供的任何帮助。
【问题讨论】:
-
你应该使用 rptAccount_ItemCommand
-
该 cmd 将插入到 aspx 页面的什么位置?还在 OnCheckChanged 事件下?