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.
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.
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.
Try this it's helpful for you,
ID Name Orders
<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;
using System.Text; using System.Xml; using System.Xml.Schema;
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 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);
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
In ItemDataBound event you can check the items and hide them or probably remove them from your repeater.
Here is an example how to use this event:
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With