I am using repeater to bind all table data.
我正在使用转发器绑定所有表数据。
And My table fields are Name,Option1,Option2... Option12. All total 13 columns. values for Option columns are dynamic. some time it contains two values for Option1 and 2 and some times figure can be change between 1 to 12.
我的表字段是Name,Option1,Option2 ...... Option12。共有13列。 Option列的值是动态的。有时候它包含Option1和2的两个值,有时候数字可以在1到12之间变化。
Now i want to show only those option columns that contain some value.
现在我想只显示那些包含某些值的选项列。
Like this:-
喜欢这个:-
Name
Option1
Option2
Option8
Name
Option10
Option12
Option4
Otion3
Name
Option5
Option7
Name
Option3
Option2
Option5
Option12
Option4
Means options are not fixed. how can i manage this with Repeater control. SO it can show value like this. Please suggest me the correct way to solve this.
手段选项不固定。我如何使用Repeater控件来管理它。所以它可以显示这样的价值。请建议我解决这个问题的正确方法。
Thanks in Advance.
提前致谢。
First Edit
首先编辑
<%# !Equals(DataBinder.Eval(Container.DataItem, "Option1")%>
....
<%# !Equals(DataBinder.Eval(Container.DataItem, "Option12")%>
Suppose i have this 12 Options like this. Now if my data source contains values only Option 1 to 5 then i need that rest of 6 to 12 options will not show on repeater.
假设我有这样的12个选项。现在,如果我的数据源仅包含选项1到5的值,那么我需要其余的6到12个选项不会在转发器上显示。
3 个解决方案
#1
3
Try this it's helpful for you,
试试这个对你有帮助,
ID Name Orders
ID名称订单
<ItemTemplate>
<tr style="background-color:FFECD8">
<td valign="top">
<%# DataBinder.Eval(Container.DataItem, "ID") %>
</td>
<td valign="top">
<%# DataBinder.Eval(Container.DataItem,"Name") %>
</td>
<td>
<asp:Repeater Runat="server" ID="ordersRepeater" EnableViewState="false"
DataSource='<%# DataBinder.Eval(Container.DataItem, "Orders") %>'>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "OrderID") %> - <%# DataBinder.Eval(Container.DataItem, "OrderName") %> - <%# DataBinder.Eval(Container.DataItem, "OrderCost")%>
<br />
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
The code behind is as follows:
背后的代码如下:
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
使用系统;使用System.Collections.Generic;使用System.Data;使用System.Data.SqlClient;使用System.Configuration;使用System.Web;使用System.Web.Security;使用System.Web.UI;使用System.Web.UI.WebControls;使用System.Web.UI.WebControls.WebParts;使用System.Web.UI.HtmlControls;
using System.Text; using System.Xml; using System.Xml.Schema;
使用System.Text;使用System.Xml;使用System.Xml.Schema;
public class Customer { private int id; public int ID { get { return this.id; } set { this.id = value; } }
public class Customer {private int id; public int ID {get {return this.id; } set {this.id = value; }}
private string name;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
public List orders;
public List Orders
{
get { return this.orders; }
set { this.orders = value; }
}
}
}
public class Order { private int orderID; public int OrderID { get { return this.orderID; } set { this.orderID = value; } } private string orderName; public string OrderName { get { return this.orderName; } set { this.orderName = value; } } private decimal orderCost; public decimal OrderCost { get { return this.orderCost; } set { this.orderCost = value; } } }
public class Order {private int orderID; public int OrderID {get {return this.orderID; } set {this.orderID = value; private string orderName; public string OrderName {get {return this.orderName; } set {this.orderName = value; private decimal orderCost; public decimal OrderCost {get {return this.orderCost; } set {this.orderCost = value; }}}
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { List orders1 = new List(); Order order1 = new Order(); order1.OrderID = 1; order1.OrderName = "Pepsi"; order1.OrderCost = 12.5M; orders1.Add(order1);
public partial class _Default:System.Web.UI.Page {protected void Page_Load(object sender,EventArgs e){List orders1 = new List();订单order1 =新订单(); order1.OrderID = 1; order1.OrderName =“百事可乐”; order1.OrderCost = 12.5M; orders1.Add(order1);
Order order2 = new Order();
order2.OrderID = 2;
order2.OrderName = "7up";
order2.OrderCost = 12M;
orders1.Add(order2);
List orders2 = new List();
Order order3 = new Order();
order3.OrderID = 4;
order3.OrderName = "Food";
order3.OrderCost = 12.5M;
orders2.Add(order3);
List customers = new List();
Customer c1 = new Customer();
c1.ID = 1;
c1.Name = "Bilal";
c1.Orders = orders1;
customers.Add(c1);
Customer c2 = new Customer();
c2.ID = 2;
c2.Name = "potterosa";
c2.Orders = orders2;
customers.Add(c2);
this.Repeater1.DataSource = customers;
this.Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
}
}
}
Go through following link
通过以下链接
http://forums.asp.net/t/1118175.aspx/1
http://forums.asp.net/t/1118175.aspx/1
#2
1
In ItemDataBound event you can check the items and hide them or probably remove them from your repeater.
在ItemDataBound事件中,您可以检查项目并隐藏它们,或者可能将它们从转发器中删除。
Here is an example how to use this event:
以下是如何使用此事件的示例:
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065
#3
0
You should use Repeater's ItemDataBound
Event to check empty column, if you find that column has values then you can display them if column has no values then you can set their visible property false.
There is a very good example for you. You must look at it.
您应该使用Repeater的ItemDataBound事件来检查空列,如果您发现该列具有值,那么您可以显示它们,如果列没有值,那么您可以将其visible属性设置为false。有一个非常好的例子。你必须看看它。
#1
3
Try this it's helpful for you,
试试这个对你有帮助,
ID Name Orders
ID名称订单
<ItemTemplate>
<tr style="background-color:FFECD8">
<td valign="top">
<%# DataBinder.Eval(Container.DataItem, "ID") %>
</td>
<td valign="top">
<%# DataBinder.Eval(Container.DataItem,"Name") %>
</td>
<td>
<asp:Repeater Runat="server" ID="ordersRepeater" EnableViewState="false"
DataSource='<%# DataBinder.Eval(Container.DataItem, "Orders") %>'>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "OrderID") %> - <%# DataBinder.Eval(Container.DataItem, "OrderName") %> - <%# DataBinder.Eval(Container.DataItem, "OrderCost")%>
<br />
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
The code behind is as follows:
背后的代码如下:
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
使用系统;使用System.Collections.Generic;使用System.Data;使用System.Data.SqlClient;使用System.Configuration;使用System.Web;使用System.Web.Security;使用System.Web.UI;使用System.Web.UI.WebControls;使用System.Web.UI.WebControls.WebParts;使用System.Web.UI.HtmlControls;
using System.Text; using System.Xml; using System.Xml.Schema;
使用System.Text;使用System.Xml;使用System.Xml.Schema;
public class Customer { private int id; public int ID { get { return this.id; } set { this.id = value; } }
public class Customer {private int id; public int ID {get {return this.id; } set {this.id = value; }}
private string name;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
public List orders;
public List Orders
{
get { return this.orders; }
set { this.orders = value; }
}
}
}
public class Order { private int orderID; public int OrderID { get { return this.orderID; } set { this.orderID = value; } } private string orderName; public string OrderName { get { return this.orderName; } set { this.orderName = value; } } private decimal orderCost; public decimal OrderCost { get { return this.orderCost; } set { this.orderCost = value; } } }
public class Order {private int orderID; public int OrderID {get {return this.orderID; } set {this.orderID = value; private string orderName; public string OrderName {get {return this.orderName; } set {this.orderName = value; private decimal orderCost; public decimal OrderCost {get {return this.orderCost; } set {this.orderCost = value; }}}
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { List orders1 = new List(); Order order1 = new Order(); order1.OrderID = 1; order1.OrderName = "Pepsi"; order1.OrderCost = 12.5M; orders1.Add(order1);
public partial class _Default:System.Web.UI.Page {protected void Page_Load(object sender,EventArgs e){List orders1 = new List();订单order1 =新订单(); order1.OrderID = 1; order1.OrderName =“百事可乐”; order1.OrderCost = 12.5M; orders1.Add(order1);
Order order2 = new Order();
order2.OrderID = 2;
order2.OrderName = "7up";
order2.OrderCost = 12M;
orders1.Add(order2);
List orders2 = new List();
Order order3 = new Order();
order3.OrderID = 4;
order3.OrderName = "Food";
order3.OrderCost = 12.5M;
orders2.Add(order3);
List customers = new List();
Customer c1 = new Customer();
c1.ID = 1;
c1.Name = "Bilal";
c1.Orders = orders1;
customers.Add(c1);
Customer c2 = new Customer();
c2.ID = 2;
c2.Name = "potterosa";
c2.Orders = orders2;
customers.Add(c2);
this.Repeater1.DataSource = customers;
this.Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
}
}
}
Go through following link
通过以下链接
http://forums.asp.net/t/1118175.aspx/1
http://forums.asp.net/t/1118175.aspx/1
#2
1
In ItemDataBound event you can check the items and hide them or probably remove them from your repeater.
在ItemDataBound事件中,您可以检查项目并隐藏它们,或者可能将它们从转发器中删除。
Here is an example how to use this event:
以下是如何使用此事件的示例:
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065
#3
0
You should use Repeater's ItemDataBound
Event to check empty column, if you find that column has values then you can display them if column has no values then you can set their visible property false.
There is a very good example for you. You must look at it.
您应该使用Repeater的ItemDataBound事件来检查空列,如果您发现该列具有值,那么您可以显示它们,如果列没有值,那么您可以将其visible属性设置为false。有一个非常好的例子。你必须看看它。