Hey Everyone! Hope you guys can help me with this. I am trying to format a datalist with the month name as headers. The issue I am facing is that the code is hiding some of the rows but I am unable to figure out why. The datasource returns 25 records without the ItemDataBound command and when I add the ItemDatabound code I get about 17 records. Basically if the name of the month is the same it should only display once and hide the duplicate month names. Here's what I have so far:
protected void DataList1_ItemDataB(object sender, System.Web.UI.WebControls.DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { string strval = ((Label)(e.Item.FindControl("lblMP"))).Text; string month = ViewState["DateAdded"] as string; ; if (month == strval) { ((Label)(e.Item.FindControl("lblMP"))).Text = ""; e.Item.Visible = false; } else { month = strval; ViewState["DateAdded"] = month; ((Label)(e.Item.FindControl("lblMP"))).Text = month; Panel pnlMonth = (Panel)e.Item.FindControl("pnlMonth"); pnlMonth.Visible = true; e.Item.Visible = true; } } }
Any ideas?