如何在多行中绑定转发器-改用DataList [英] How to bind the repeater in multiple rows - use DataList instead
问题描述
嗨..
我陷入了一个不寻常的问题.
我正在asp.net中的Webform上工作.我需要将一对值绑定到转发器(或datagrid或datalist)控件.总共有40对,我绑定到中继器.中继器itemtemplate具有一个Label和一个Textbox,这些值的每个数据集都绑定到该Label和Textbox.
我的问题是,这会生成一个带有40个文本框的中继器(水平上方带有垂直的标签),而这不适合我的屏幕.在绑定约6个数据项之后,是否有任何方法可以将itemtemplate控件移至nextrow,以便每个转发器行最多具有一组6个文本框,并在垂直方向扩展并添加新项?
Hi..
I am stuck in a unusual issue.
I am working on a webform in asp.net. I need to bind a pair of values to the repeater (or datagrid or datalist) control. There are 40 pairs in all and I am binding to the repeater. The repeater itemtemplate has a Label and a Textbox to which each of this set of values is databound to.
My issue is that this generates a repeater with 40 textboxes (with label vertically above it) horizontally and this does not fit onto my screen. Is there any way that I can move the itemtemplate controls to nextrow after some 6 dataitems are bound so that each repeater row will have a group of maximum of 6 textboxes and will expand vertically with new items added ?
<table cellpadding="3" cellspacing="0" border="0">
<tr class="rowHeading">
<td height="10px" align="left" valign="top">
Monthly:
</td>
</tr>
<tr>
<td align="left" valign="top">
<table cellpadding="3" cellspacing="0" border="0">
<tr>
<td align="left">
<table cellpadding="3" cellspacing="0" border="0" id="tblMonths">
<tr>
<asp:Repeater ID="rptMonths" runat="server">
<itemtemplate>
<td align="left" valign="top">
<asp:Literal ID="ltrMonthName" Text='<%# Eval("name") %>' runat="server"><br />
<asp:TextBox ID="txtMonthName" CssClass="RightAlignText" Width="60px" autocomplete="off"
runat="server">%<br />
<asp:TextBox ID="lblMonthName" CssClass="RightAlignText" TabIndex="1000" Width="60px"
ReadOnly="true" runat="server">
</td>
</itemtemplate>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
推荐答案
foreach (PrivacySettingsDto objPrivacySettingsDto in SettingsDto)
{
string strmessage="Hello";
Label objLabel = new Label ();
objLabel.text = strmessage.tostring();
TextBox objTextBox = new TextBox ();
objTextBox .text = strmessage.tostring();
this.repeater.Controls.Add(objLabel);
this.repeater.Controls.Add(objTextBox);
this.repeater.Controls.Add (new HtmlGenericControl("br"));
}
试试这个
Try this
Hurrey..我使用了DataList控件而不是转发器.它具有RepeatColumns属性.只需将其设置为6就能让我开心...
谢谢朋友们
Hurrey.. I used a DataList control instead of the repeater. It has the RepeatColumns property. Simply setting it to 6 made my day...
Thank you friends
<asp:datalist id="dlMonths" runat="server" repeatcolumns="6" mode="hold" xmlns:asp="#unknown" /> <ItemTemplate>
<td align="left" valign="top">
<asp:Literal ID="ltrMonthName" Text='<%# Eval("name") %>' runat="server"></asp:Literal><br />
<asp:TextBox ID="txtMonthName" CssClass="RightAlignText" Width="60px" autocomplete="off"
runat="server"></asp:TextBox>%<br />
<asp:TextBox ID="lblMonthName" CssClass="RightAlignText" TabIndex="1000" Width="60px"
ReadOnly="true" runat="server"></asp:TextBox>
</td>
</ItemTemplate>
</asp:DataList>
这篇关于如何在多行中绑定转发器-改用DataList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!