I am creating a repater column programmatically, I can' t do with loops, please help me! -
-
-
<%
-
foreach (string strTest in getRepeaterItemColumnName())
-
{
-
%>
-
<%# DataBinder.Eval(Container.DataItem, strTest) %>
-
<%
-
}
-
%>
-
-
This syntax wrong because strTest does not local varible ! - what is correct syntax?
Thank You..
8 9907
Shouldn't this be: -
<%
-
foreach (string strTest in getRepeaterItemColumnName())
-
{
-
DataBinder.Eval(Container.DataItem, strTest)
-
}
-
%>
-
I am creating a repater column programmatically, I can' t do with loops, please help me! -
-
-
<%
-
foreach (string strTest in getRepeaterItemColumnName())
-
{
-
%>
-
<%# DataBinder.Eval(Container.DataItem, strTest) %>
-
<%
-
}
-
%>
-
-
This syntax wrong because strTest does not local varible ! - what is correct syntax?
Thank You..
Is this a PHP question?
Whenever I've used repeaters I've never had to loop through the DataSource.
I simply set the Repeater's DataSource and performed a DataBind...the ASP.NET technology took care of the rest...
Example of what it would look like:
(This is not going to work as is) -
<asp:Repeater ID="MyRepeater" runat="server">
-
<ItemTemplate>
-
<%# DataBinder.Eval(Container.DataItem, strTest) %>
-
</ItemTemplate>
-
</asp:Repeater>
-
-
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
-
MyRepeter.DataSource = _myStringTestArray
-
MyRepeater.DataBind()
-
End Sub
-Frinny
Shouldn't this be: -
<%
-
foreach (string strTest in getRepeaterItemColumnName())
-
{
-
DataBinder.Eval(Container.DataItem, strTest)
-
}
-
%>
-
Hi Plater
This code not correct, Because databinder method not working between <% %> block
Databinder metod working between <%# %> block "#"
Error : The name 'Container' does not exist in the current context
Is this a PHP question?
Whenever I've used repeaters I've never had to loop through the DataSource.
I simply set the Repeater's DataSource and performed a DataBind...the ASP.NET technology took care of the rest...
Example of what it would look like:
(This is not going to work as is) -
<asp:Repeater ID="MyRepeater" runat="server">
-
<ItemTemplate>
-
<%# DataBinder.Eval(Container.DataItem, strTest) %>
-
</ItemTemplate>
-
</asp:Repeater>
-
-
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
-
MyRepeter.DataSource = _myStringTestArray
-
MyRepeater.DataBind()
-
End Sub
-Frinny
Hi
question is not PHP ! ( has been used wrong tag in a HTML editor)
I am know Repeater, DataSource, DataBind .Ado.NET etc.
My problem ( DataBinder.Eval(Container.DataItem, "column name") ) Manual writing string "column name" I want to dynamic column name I use getRepeaterItemColumnName function -
protected Array getRepeaterItemColumnName()
-
{
-
string[] array = { "tbl_time", "tbl_date", "tbl_status"};
-
return array;
-
}
-
-
Sorry I so so speaking English
Hi -
protected Array getRepeaterItemColumnName()
-
{
-
string[] array = { "tbl_time", "tbl_date", "tbl_status"};
-
return array;
-
}
-
-
Sorry I so so speaking English
Here's an example of a table with dynamically created columns: -
<table id="MyRepeaterTable" border="1" cellpadding="0" cellspacing="0" height="<%= TableHeight() %>px" >
-
<!-- TableHeight() is a property of my control-->
-
<tr>
-
<asp:Repeater ID="MyRepeater" runat="server">
-
<ItemTemplate>
-
<th id="<%# DataBinder.Eval(Container.DataItem, "HeaderID") %>">
-
<%# DataBinder.Eval(Container.DataItem, "HeaderTitle") %>
-
</th>
-
</ItemTemplate>
-
</asp:Repeater>
-
</tr>
-
</table>
-
-
Public Partial Class MyExampleOfRepeater
-
Inherits System.Web.UI.UserControl
-
-
Private _columns As ArrayList
-
Private _columnNames() As String = { "tbl_time", "tbl_date", "tbl_status"}
-
Private _height As String = "24"
-
-
Public Property Height() As String
-
Get
-
return _value
-
End Get
-
Set(ByVal value As String)
-
_height = value
-
End Set
-
-
End Property
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
For i As Integer = 0 to _columnNames.Length-1
-
_columns.Add(New ColumnTitle(i.ToString,_columnNames(i)))
-
Next
-
End Sub
-
-
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
-
MyRepeater.DataSource = _columns
-
MyRepeater.DataBind
-
End Sub
-
-
-
Private Class ColumnTitle
-
Private _name As String
-
Private _id As String
-
Public ReadOnly Property HeaderID As String
-
'This property is used by the ASP call: <%# DataBinder.Eval(Container.DataItem, "HeaderID") %>
-
Get
-
Return _id
-
End Get
-
End Property
-
Public ReadOnly Property HeaderTitle As String
-
'This property is used by the ASP call: <%# DataBinder.Eval(Container.DataItem, "HeaderTitle") %>
-
Get
-
Return _name
-
End Get
-
End Property
-
-
Public Sub New(ByVal id As String, ByVal title As String)
-
_id = id
-
_title = title
-
End Sub
-
-
End Class
-
-
End Class
-
Please note that the above code has not been tested and is not guaranteed to work.
Hi Frinavale
Thanks for your message, latest post it is not working ! (I could not make work)
I am trying another metod -
-
<script runat="server" >
-
string _i = "";
-
</script>
-
-
<asp:Repeater ID="rptData" runat="server" OnItemCommand="rptData_ItemCommand">
-
-
<ItemTemplate>
-
<tr onmouseover="this.bgColor='#F4F4F4';" onmouseout="this.bgColor='#FFFFFF';">
-
<% foreach (string aa in getset())
-
{
-
_i = aa.ToString();
-
Response.Write(aa.ToString()); // for test
-
-
%>
-
<td><%# DataBinder.Eval(Container.DataItem, _i.ToString()) %></td>
-
<% } %>
-
</tr>
-
</ItemTemplate>
-
</asp:Repeater>
-
-
-
protected Array getset() // for test
-
{
-
string[] array = { "tbl_time", "tbl_date", "tbl_status"} };
-
return array;
-
}
-
-
-- What new - string _i = ""; (Because accessing protected variables for Databinding Expressions syntax)
- I want to replace _i at runtime in foreach loops
--Problem - _i is not replaced at runtime (loop item by item)
Or - <td><%# DataBinder.Eval(Container.DataItem, getcolumnname(0))%></td>
- 0 (int arguments) = Array item ( return array[0];)
- Problem int arguments (How can you I do to redouble ++)
Do you have any ideas ?
Thx.
Hi Frinavale
Thanks for your message, latest post it is not working ! (I could not make work)
I am trying another metod -
-
<script runat="server" >
-
string _i = "";
-
</script>
-
-
<asp:Repeater ID="rptData" runat="server" OnItemCommand="rptData_ItemCommand">
-
-
<ItemTemplate>
-
<tr onmouseover="this.bgColor='#F4F4F4';" onmouseout="this.bgColor='#FFFFFF';">
-
<% foreach (string aa in getset())
-
{
-
_i = aa.ToString();
-
Response.Write(aa.ToString()); // for test
-
-
%>
-
<td><%# DataBinder.Eval(Container.DataItem, _i.ToString()) %></td>
-
<% } %>
-
</tr>
-
</ItemTemplate>
-
</asp:Repeater>
-
-
-
protected Array getset() // for test
-
{
-
string[] array = { "tbl_time", "tbl_date", "tbl_status"} };
-
return array;
-
}
-
-
-- What new- string _i = ""; (Because accessing protected variables for Databinding Expressions syntax)
- I want to replace _i at runtime in foreach loops
--Problem - _i is not replaced at runtime (loop item by item)
Or - <td><%# DataBinder.Eval(Container.DataItem, getcolumnname(0))%></td>
- 0 (int arguments) = Array item ( return array[0];)
- Problem int arguments (How can you I do to redouble ++)
Do you have any ideas ?
Thx.
I'm not that great with C# so I'm going to give you an example in VB.NET
You should not have a for loop within your repeater...the purpose of a repeater is to "Repeat" through all of the items in the data source that it's bound to.
Your code should look something like this: -
<table border="1">
-
<tr onmouseover="this.bgColor='#F4F4F4';" onmouseout="this.bgColor='#FFFFFF';">
-
<asp:Repeater ID="rptData" runat="server">
-
<ItemTemplate>
-
<td><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
-
</ItemTemplate>
-
</asp:Repeater>
-
</tr>
-
</table>
-
Your server side code should look something like this (only in C# instead of VB) -
-
Private arr() As String = {"tbl_time", "tbl_date", "tbl_status"}
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
Dim titles As New ArrayList
-
For Each s As String In arr
-
titles.Add(New ColumnTitle(s))
-
Next
-
rptData.DataSource = titles
-
rptData.DataBind()
-
End Sub
-
-
Private Class ColumnTitle
-
Private _name As String
-
Public Property Name() As String
-
Get
-
Return _name
-
End Get
-
Set(ByVal value As String)
-
_name = value
-
End Set
-
End Property
-
Public Sub New(ByVal name As String)
-
_name = name
-
End Sub
-
End Class
-
Please note that the "Name" attribute in the following ASP code:
<%#DataBinder.Eval(Container.DataItem, "Name")%>
Refers to the Public Property Name in the ColumnTitle class.
When you use this, you have to call a Property of the Object that you are using as your data source for your repeater. The .ToString() will not work in this ASP call either.
So, we create an object that has a property that returns a string so that it can be displayed in your table. The Object in this example is the ColumnTitle class. We use an array of ColumnTitles as the source for our repeater. This way we can grab the Container.DataItem (which is the ColumnTitle object) and grab the value of the property we wish to display (the Name property).
Try this and see if it works for you.
-Frinny
- <%for (int c = 0; c < RepeatColumns.Count; c++)
-
{
-
%>
-
<td style="border: solid 1pt black; border-right: none 0pt white; border-top: none 0pt white">
-
<%#DataBinder.Eval(Container.DataItem, RepeatColumns[Count] + "Total SLA")%>
-
</td>
-
<td style="border: solid 1pt black; border-right: none 0pt white; border-top: none 0pt white">
-
<%#DataBinder.Eval(Container.DataItem, RepeatColumns[Count] + "Met")%>
-
</td>
-
<td style="border: solid 1pt black; border-right: none 0pt white; border-top: none 0pt white">
-
<%#DataBinder.Eval(Container.DataItem, RepeatColumns[Count] + "Not Met]")%>
-
</td>
-
<td style="border: solid 1pt black; border-right: none 0pt white; border-top: none 0pt white">
-
<%#DataBinder.Eval(Container.DataItem, RepeatColumns[Count] + "NA")%>
-
</td>
-
<td style="border: solid 1pt black; border-right: none 0pt white; border-top: none 0pt white">
-
<%#DataBinder.Eval(Container.DataItem, RepeatColumns[Count] + "Met % age]")%>
-
</td>
-
<%
-
Count++;
-
}
-
%>
1. The RepeatColumns contains List of Months declared as a property in code behind
2. Count is an integer, declared as a property in code behind
And the out is as follows:
Try it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ashish Shridharan |
last post by:
Hi All
I have been trying to add a control to the header cell of
a datagrid on my ASP.NET page. These controls are defined
in the HTML as ASP.NET web controls.
They are being added into the...
|
by: Dmitri Shvetsov |
last post by:
Hi All,
Is it possible at all, and if yes, then how? Or it's very/extremely hard to
do that? Maybe somebody knows...)
I'm writing a Web App using VS2003/C#/MSSQL.
I'm currently having about...
|
by: Mike P |
last post by:
I have a Hyperlink Column which I need to convert to a Template Column
so that I can pass multiple parameters.
My current code is like this and works for a single parameter:
...
|
by: JenHu |
last post by:
I have a datagrid (dgFundStatus) which displays a
column.
When the Transmit_Date is null, how can I show "Not transmit yet"
instead of null?
Thanks.
Sub BindData()
Dim strSql As New...
|
by: Red |
last post by:
Hi all,
I would like to ask how to combine 2 field into one
column.
For example I have field first name and last name. When I
show it to the datagrid I want to show it as one column,
for...
|
by: Ben Fidge |
last post by:
I'm using DataList to present tabular data but am often having problems with
some rows column alignment being out of synch with the rest of the rows.
My DataList looks similar to this...:
...
|
by: Sathyaish |
last post by:
I want to display a column in a datagrid such that each item/row in
that column acts as a hyperlink. Further, when I click on the
hyperlink, it doesn't redirect to another page or even to itself....
|
by: Agnes |
last post by:
I got a grid list the record, column1 is "number"
When the user press colunn 1 , i want to show out the pdf file whose
filename is same as column1's contents
How can I do that ?? thanks a lot
<a...
|
by: SunshineInTheRain |
last post by:
The following code is dynamic create dropdownmenu which data within pulled from database
However, the code work well on IE but not on Firefox. On Firefox, the whole mouseover and mouseout function...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |