Forum Discussion
aspnet c# iterate control in listview and remove a panel from placeholder in one column
trying to iterate through controls in listview to remove panel01 from placeholder if detected row in database condition dt.Rows[i]["BidEndWithError"].ToString() == "no" in the row:
But all the listview's panel01 being removed even dt.Rows[i]["BidEndWithError"].ToString() == "no" is not 'no'`your text`
`<asp:PlaceHolder ID="phLabel" runat="server">
<asp:Panel ID="panel01" runat="server">Day Left : <%# Eval("BidDayLeft") %></br>
Hour Left : <%# Eval("BidHourLeft") %></br>
Minute Left : <%# Eval("BidMinuteLeft") %></br>
Second Left : <%# Eval("BidSecondLeft") %></br></asp:Panel>
protected void lv01_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{string constr = ConfigurationManager.ConnectionStrings["bidsystemdb"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{DataTable dt = new DataTable();
//string strSQL = "Select * from BidTable2 WHERE ProductName='Toy 1'";
string strSQL = "Select * from BidTable2";SqlDataAdapter adpt = new SqlDataAdapter(strSQL, con);
adpt.Fill(dt);
for (int ij = 0; ij < e.Item.Controls.Count; ij++)
{for (int i = 0; i < dt.Rows.Count; i++)
{//Response.Write("lv01 reached!");
if (dt.Rows[i]["BidEndWithError"].ToString() == "no")
{Response.Write("lv01 level 2 reached!");
PlaceHolder _phLabel = e.Item.Controls[ij].FindControl("phLabel") as PlaceHolder;
Panel _pnlLabel = e.Item.Controls[ij].FindControl("panel01") as Panel;
_phLabel.Controls.Remove(_pnlLabel);
ContentPlaceHolder _MainContent = Master.FindControl("MainContent") as ContentPlaceHolder;
UpdatePanel _udp01 = _MainContent.FindControl("udp01") as UpdatePanel;
_udp01.Update();
}
}
}
}}
}`