我有一个转发器,我有一些控件,如下拉列表和文本框,我如何能够捕获下拉选择值和在文本框中输入的值并将它们存储在隐藏字段中?
这就像公式Left(c1+c2)*c3
格式是这样的。
答案 0 :(得分:1)
转发器代码:
<asp:Repeater ID='myRepeater' runat="server" OnItemDataBound='myRepeater_OnItemDataBound'>
<ItemTemplate>
<asp:HiddenField ID='myHidden' runat="server" />
<asp:DropDownList ID="GeneralDDL" runat="server" AutoPostBack="True" />
</ItemTemplate>
</asp:Repeater>
**Code behind :**
protected void myRepeater_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
var myHidden = (HiddenField)e.Item.FindControl("myHidden");
foreach(RepeaterItem dataItem in 'myRepeater.Items)
{
myHidden.Value = ((DropDownList)'myRepeater.FindControl("GeneralDDL")).SelectedItem.Text;
// Same like for Text box
}
}