如何区分 ASP.Net Repeater 控件生成的 HTML 发布的数据?
因此,我在表单中使用中继器来显示从数据库检索的问题列表。 每个问题都允许最终用户选择是或否,并添加一些像这样的附加文本。
<ItemTemplate>
<asp:Panel runat="server">
<asp:RadioButtonList RepeatDirection="Horizontal" CssClass="YesNo" ID="YesNo" runat="server">
<asp:ListItem Value="Yes" Text="Yes" />
<asp:ListItem Value="No" Text="No" />
</asp:RadioButtonList>
</asp:panel>
<asp:Panel runat="server" CssClass="MoreInfo">
<asp:TextBox ID="TextBox1" TextMode="MultiLine" Height="70px" Rows="10" Columns="25" Wrap="true" runat="server" CssClass="MoreInfoText"></asp:TextBox>
</asp:Panel>
</ItemTemplate>
中继器在 PageLoad 事件中与数据表进行数据绑定。 数据表中的字段之一是问题的编号。 那么,当发布数据时,我如何才能知道每个答案(是或否以及附加文本)所指的是哪个问题?
如果我手动生成 HTML,而不是使用服务器控件,我可以只创建将发布数据的 html 元素的名称,例如
name=variableHoldingQuestionNumber + YesNo
name=variableHoldingQuestionNumber + AdditionalComments
但在中继器项内设置 Name 属性时,我似乎无法使用变量。 放弃服务器控制并自己编写 HTML 是我唯一的解决方案。
So I am using a Repeater inside a form to display a list of questions that are retrieved from a database.
Each Question allows the end user to select Yes or No and add some additional Text like this.
<ItemTemplate>
<asp:Panel runat="server">
<asp:RadioButtonList RepeatDirection="Horizontal" CssClass="YesNo" ID="YesNo" runat="server">
<asp:ListItem Value="Yes" Text="Yes" />
<asp:ListItem Value="No" Text="No" />
</asp:RadioButtonList>
</asp:panel>
<asp:Panel runat="server" CssClass="MoreInfo">
<asp:TextBox ID="TextBox1" TextMode="MultiLine" Height="70px" Rows="10" Columns="25" Wrap="true" runat="server" CssClass="MoreInfoText"></asp:TextBox>
</asp:Panel>
</ItemTemplate>
The repeater is databound to a datatable in the PageLoad event.
One on the fields in the datatable is the Question's number.
So when the data is posted how can I tell which question # each answer (Yes or No and additional Text) is refering to?
If I were generating the HTML by hand instead of using a Server Control I could just make the name of the html element that will be posting data like
name=variableHoldingQuestionNumber + YesNo
name=variableHoldingQuestionNumber + AdditionalComments
But I can't seem to use a variable when setting the Name attribute inside a Repeater Item.
Is abandoning the Server Control and writing the HTML myself my only solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将问题编号绑定到隐藏字段,当保存返回时,抓住该隐藏字段并从中取出编号。然后你就知道你在看哪个问题。
Bind the questions number to a hidden field and when the save comes back, grab that hidden field back off and take the number out of it. Then you know which question you are looking at.
在页面加载时设置断点并进行回发。深入研究 Request.Form 键/值对集合。帖子中的所有内容都将在那里,并带有可预测的标签/索引。
Put a break point on page load and do a postback. Take a deep look at Request.Form key/value pair collection. Everything from the post will be in there, with predictable labels/indexs.