0

My application till today we running absolutely fine. I usually follow below steps before I upload the files to web-server: 1. Re-Build solution 2. Open all web form in the browsing (debugging the code) 3. Publish the code

Below is the problem which I am facing with my default.aspx page. When I am adding below code of repeater at the code behind (.cs) file. The no compilation error is shwon but at the run time browser goes freezzed. Nothing happens and the entire system gets hang. Not even Ctrl+Shift+Del is working.

Description of my code - I have data in a table 'tb'. Date in the first row of 'tb' has already been displayed hence now I only want remaining 4 rows of the 'tb' table in another DataTable with less number of columns - link, text, author and date.

Hence I created a new DataTable 'n'with the help of a loop I have copied the data for these 4 columns from 'tb' to 'n'. Finally, I have binded this data to the Repeater control on the aspx page.

Please check and help me why code below is freezing my entire application and system as well.

C# code:

DataRow r = tb.Rows[0];
                    r.Delete();
                    tb.AcceptChanges();
                    DataTable n = new DataTable();
                    DataColumn dc;
                    DataRow dr;

                    dc = new DataColumn();
                    dc.DataType = typeof(String);
                    dc.ColumnName = "link";
                    n.Columns.Add(dc);

                    dc = new DataColumn();
                    dc.DataType = typeof(String);
                    dc.ColumnName = "text";
                    n.Columns.Add(dc);

                    dc = new DataColumn();
                    dc.DataType = typeof(String);
                    dc.ColumnName = "author";
                    n.Columns.Add(dc);

                    dc = new DataColumn();
                    dc.DataType = typeof(String);
                    dc.ColumnName = "date";
                    n.Columns.Add(dc);

                    int c = tb.Rows.Count;
                    for (int i = 0; i < c; c++)
                    {
                        dr = n.NewRow();
                        dr["link"] = base_url + "/post/" + tb.Rows[i]["post_type"].ToString() + "/" + tb.Rows[i]["blog_post_id"].ToString() + "/" + u.get_url_friendly_text(30, tb.Rows[i]["blog_Title"].ToString());
                        dr["text"] = tb.Rows[i]["blog_Title"].ToString();
                        dr["author"] = tb.Rows[i]["author"].ToString();
                        dr["date"] = Convert.ToDateTime(tb.Rows[i]["last_updated"]).ToString("MMMM dd, yyyy");
                        n.Rows.Add(dr);
                    }

                    Repeater1.DataSource = n;
                    Repeater1.DataBind();

asp.net code for repeater control from .aspx page

<div class="col-lg-5 news_col">
                        <div class="news_posts_small">
                            <asp:Repeater ID="Repeater1" runat="server">
                                <ItemTemplate>

                                    <!-- News Posts Small -->
                            <div class="news_post_small">
                                <div class="news_post_small_title"><a href="<%# Eval("link") %>"><%# Eval("text") %></a></div>
                                <div class="news_post_meta">
                                    <ul>
                                        <li><a href="#"><%# Eval("author") %></a></li>
                                        <li><a href="#"><%# Eval("date") %></a></li>
                                    </ul>
                                </div>
                            </div>

                                </ItemTemplate>
                            </asp:Repeater>
                        </div>
                    </div>

FYI I am using VS 2019 and asp.net V4.5 for this web application.

Apart from this page - remaining pages are working fine. Also when I will remove this code this page will also work smoothly.

Jay
  • 7
  • 1
  • Try redoing this line `for (int i = 0; i < c; c++)` Look carefully at what is happening. – VDWWD May 23 '20 at 09:17

1 Answers1

0

This is probably because the loop doesn't end.

for (int i = 0; i < c; c++)

Your for loop is adding after each loop a 1 to the 'c' variable, this should be 'i' like so:

for (int i = 0; i < c; i++)
Lucdabomb
  • 87
  • 8
  • Ahh - At the back end of mind, had the same logic and checked this loop twice - may be due to frustraction of hong hours - I missed it. Thank you. This worked for me. I appriciate you efforts! – Jay May 23 '20 at 10:26