RBX
In the zone
Read this after reading the "Edit" section below
I'm fetching 3 records, and maybe because the div I added last isn't included in 'lb_left_inner', I only get one.
EDIT:
I decided to use this, and I think this does the job
s = s.Substring(0, s.Length - 6);
still, I can get only 1 division added to the previous content.
I am encountering a problem which I think is related to TrimEnd method.
I have following markup
I'm taking HTML of div 'lb_left_inner', trimming '</div>' from its end, adding some HTML to it and putting it all back inside the div 'lb_left'.
My inspection show that TrimEnd is not working as expected (or maybe I'm missing something else).
variable s before TrimEnd
*i.imgur.com/fztPd.png
after TrimEnd
*i.imgur.com/0AxOp.png
I have following markup
Code:
<div class="listbox-content">
<h4 class="listbox-heading">
Latest Properties</h4>
<div class="lb-left" id="lb_left" runat="server">
<div id="lb_left_inner" runat="server">
<div class="inner-cont">
<asp:Image ID="Image1" ImageUrl="~/images/slider-img02.jpg" runat="server" />
</div>
<div class="inner-cont">
<asp:Image ID="Image3" ImageUrl="~/images/slider-img01.jpg" runat="server" />
</div>
<div class="inner-cont">
<asp:Image ID="Image5" ImageUrl="~/images/slider-img03.jpg" runat="server" />
</div>
</div>
</div>
<%-- some other div, commented --%>
</div>
I'm taking HTML of div 'lb_left_inner', trimming '</div>' from its end, adding some HTML to it and putting it all back inside the div 'lb_left'.
Code:
protected void Page_Load(object sender, EventArgs e) {
BLL rbll = new BLL();
char[] endDiv = new char[] { '<', '/', 'd', 'i', 'v', '>' };
try {
DataTable dt = rbll.SelectAllProperties();
foreach (DataRow dr in dt.Rows) {
string[] arr = new string[dt.Columns.Count];
int i = 0;
foreach (DataColumn dc in dt.Columns) {
arr[i] = dr[dc].ToString();
i++;
}
System.Text.StringBuilder sb = new System.Text.StringBuilder();
lb_left_inner.RenderControl(new HtmlTextWriter(new System.IO.StringWriter(sb)));
string s = sb.ToString();
for (int x = 0; x < 5; x++)
s = s.TrimEnd(endDiv);
this.lb_left.InnerHtml = s + "<div class=\"inner-cont\"><img src=\"" + arr[16].TrimStart(new char[] {'~','/'}) + "\" runat=\"server\"/><h3 class=\"room-type\">Rent a commercial room</h3><p>Jaipur, IX ker<br />105 000 Ft/mo<br />75 m2 / 3 bed / 1 liv / 1 bath</p><a class=\"more\">More Details</a></div>" + "</div>";
}
} catch (Exception exc) {
Response.Write("<h1>" + exc.Message + "</h1>");
} finally {
rbll = null;
//sb = null;
}
}
My inspection show that TrimEnd is not working as expected (or maybe I'm missing something else).
variable s before TrimEnd
*i.imgur.com/fztPd.png
after TrimEnd
*i.imgur.com/0AxOp.png
*i.imgur.com/mKrgo.png
EDIT:
I decided to use this, and I think this does the job
s = s.Substring(0, s.Length - 6);
still, I can get only 1 division added to the previous content.