Click here to Skip to main content
15,891,799 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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 ?

ASP.NET
<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>
Posted
Updated 21-Nov-11 3:50am
v3
Comments
sriman.ch 17-Nov-11 4:21am    
can you provide the aspx where you have placed your repeater control ?
bbirajdar 17-Nov-11 5:04am    
The repeater is placed on the page in HTML table just after the form tag.

Edit- Updated my question with the aspx code

C#
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
 
Share this answer
 
v2
Comments
André Kraak 17-Nov-11 5:17am    
Edited answer:
Added pre tags
Formatted text/code
bbirajdar 17-Nov-11 6:36am    
Thank you for the help. But this does not solve my problem. You code adds the Label and Textbox group as 'one group per row'.

What I want is a such a set of 6 Labels and Textboxes to be in one row and when the datasource contains more than 6 such pairs then the repeater should move to to the next row and so on.
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.NET
<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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900