max table columns in Repeater control

  • Thread starter Thread starter Brian W
  • Start date Start date
B

Brian W

I have an array of strings:

s[0] = "string 0";
s[1] = "string 1";
s[2] = "string 2";
s[3] = "string 3";
s[4] = "string 4";
s[5] = "string 5";
s[6] = "string 6";
s[7] = "string 7";
s[8] = "string 8";
s[9] = "string 9";
s[10] = "string 10";

and I want to display them in a table using a Repeater(?) like this:

"string 0" "string 1" "string 2" "string 3" "string 4"
"string 5" "string 6" "string 7" "string 8" "string 9";
"string 10"

Is something like this possible with a Repeater? How? Example?


TIA
Brian W
 
Hi,

Yes it possible but with DataList:

you need to add lable to your DataList and bind it to container
dataitem. then set your array as DataList datasource and bind array to
DataList:

Page ASPX file :

<asp:DataList id="DataList2" style="Z-INDEX: 106; LEFT: 219px; POSITION:
absolute; TOP: 270px"
runat="server" Height="82" Width="231" RepeatDirection="Horizontal"
RepeatColumns="4">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem") %>'>
</asp:Label>
</ItemTemplate>
</asp:DataList>

page code behind :

string[] s = new string[11];
s[0] = "string 0";
s[1] = "string 1";
s[2] = "string 2";
s[3] = "string 3";
s[4] = "string 4";
s[5] = "string 5";
s[6] = "string 6";
s[7] = "string 7";
s[8] = "string 8";
s[9] = "string 9";
s[10] = "string 10";

this.DataList2.DataSource = s;
DataList2.DataBind();

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Hi Brian,

Based on my understanding, you want to display a string array every 5 items
per row in a table in Asp.net.

Instead of using Repeater control, I think DataList may be more suitable
for you. Do like this:

private void Page_Load(object sender, System.EventArgs e)
{
string [] arr=new string[11];
for(int i=0;i<11;i++)
{
arr="string"+i;
}
this.DataList1.DataSource=arr;
this.DataList1.DataBind();
}

<asp:DataList id="DataList1" RepeatColumns="5" RepeatDirection="Horizontal">
<ItemTemplate>
<%# Container.DataItem.ToString()%>
</ItemTemplate>
</asp:DataList>

=============================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top