开发者

How to pass data list to Views

Actually i want to generate a list of applicants (more than 1000) on a view for that i am using sql data reader and genrting a List and passing to Views but it is taking big time(4 to 5 second) to show on View when records are more than 500 is this normal .

{

public static ApplicantsList GetListSend(string category, string subDiv) { string os = "N"; if (category == "SCOS") os = "Y"; Applicant App;//Applicant Class Contains Name,Address,Phone etc//// ApplicantsList AppList = new ApplicantsList();//ApplicantLst Class List type// string sqlcon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString(); SqlConnection con = new SqlConnection(sqlcon); con.Open(); string SqlQuery = "SELECT [idno], [ApplicantName], [Address], [Status], convert(varchar(10), DateOfApplication,103) as DateOfApplication FROM [SCOBC] where (status = 'Pending With Dealing Assistant' and category='" + category + "') and SubDiv ='" + subDiv + "' and os ='" + os + "' order by idno"; SqlCommand cmd = new SqlCommand(SqlQuery, con); SqlDataReader sdr = null; sdr = cmd.ExecuteReader(); if (sdr.HasRows) { while (sdr.Read()) { 开发者_开发问答 App = new Applicant(); App.IdNo = sdr["idno"].ToString(); App.Name = sdr["ApplicantName"].ToString(); App.Address = sdr["Address"].ToString(); App.Status = sdr["Status"].ToString(); App.DateOfApp = sdr["DateOfApplication"].ToString(); AppList.Add(App);

            }
            sdr.Close();
            con.Close();
        }
        return AppList;
    }

}


I don't know if it is normal that your database call takes 4-5s but what is not normal is showing a list of 1000 items on a single view without implementing paging.

When you implement paging not only you will make your page smaller and easier to read from the users but will greatly improve performance as you will be fetching only what's needed. Of course in order for this to be effective the paging must be done on the SQL Server.


It is not unusual to see a page with so much data take a long time to render. The next step is to determine which part of the pages life cycle is taking up so much time. It could be the SQL call, the rendering of the HTML, or something else but you really need to limit the scope of the problem to effectively plan how you are going to fix it. I have seen it where the SQL query is really fast but with tons of data the HTML page is so large that it takes the web browser forever to render it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜