我有来自数据库的表这个表在我的asp页面中有400000行我的下拉列表(ddlPlaintiffName)从这个方法填充
private void FillPlaintiff()
{
//declare connection by pass connection string from web.config
SqlConnection sqlcon = new SqlConnection
(ConfigurationManager.ConnectionStrings["SystemConn"].ConnectionString);
//declare sql statment as astring variable
SqlCommand sqlcom = new SqlCommand();
sqlcom.Connection = sqlcon;
sqlcom.CommandType = CommandType.StoredProcedure;
sqlcom.CommandText = "proc_SelectPlaintiff";
DataTable ds = new DataTable();
//fill data set with data adabter that contain data from database
// sad.Fill(ds);
sqlcon.Open();
SqlDataAdapter sad = new SqlDataAdapter(sqlcom);
sad.Fill(ds);
ddlPlaintiffName.DataSource = ds;
ddlPlaintiffName.DataBind();
ddlPlaintiffName.Items.Insert(0, "--select --");
sqlcon.Close();
}
但每次回发我的负载都非常慢,我怎么能避免这种情况
3 回答
@Oded的答案是最好的选择 . 我认为这样的DropDownList没有任何意义 .
另一方面,时间问题很难避免 . 你可以使用
ViewState
,但400,000行就像......太多了!也许,如果您解释存储在此表中的数据类型,我们可以考虑另一种方法来执行此操作首先,说“不要这样做”的评论和答案是正确的 - 对于用户而言,使用超过几十个项目的下拉几乎总是无用的 .
其次,你的问题的答案 - 如果你能't change the user interface - is to introduce caching. There are several ways of doing this; which one you chose kinds depends on the specific bottleneck, but I'开始阅读this .
首先,你不应该在下拉列表中使用这么大的表 . 由于用户无法轻易找到 Value ,因此对他没有用处 . 你应该提供某种搜索,并根据搜索条件,虽然ajax,数据应显示在下拉列表中 . 搜索应该仅在用户输入三个或更多字符时启动,否则基于ajax的查询也会变慢 .
请参阅以下页面以获得一个想法
jQuery Searchable DropDown Plugin Demo