如何清除sqlDataReader绑定的asp:ListView行
本文关键字:asp ListView 绑定 sqlDataReader 何清除 清除 | 更新日期: 2023-09-27 18:25:13
当点击sqlDataReader绑定的清除按钮列表视图时,我在清除列表视图时遇到问题,我想清除清除按钮上的列表视图下面我附上我的代码
if (Page.Request.Params["__EVENTTARGET"] != null)
{
if (Page.Request.Params["__EVENTTARGET"].ToString().ToLower().Contains("btncheck"))
{
string[] arg = Page.Request.Params["__EVENTARGUMENT"].ToString().Split(',');
lsvSearchResult.DataSource = null;
lsvSearchResult.DataBind();
if (Convert.ToString(arg[0]) == "IDNO")
{
if (Convert.ToString(arg[1]).Trim() != "")
{
lsvSearchResult.DataSource = GetStudents(arg[0], arg[1]);
lsvSearchResult.DataBind();
}
}
else if (Convert.ToString(arg[0]) == "NAME")
{
lsvSearchResult.DataSource = GetStudents(arg[0], arg[1]);
lsvSearchResult.DataBind();
}
}
//GetStudents(arg[0], arg[1]);
}
else if (Page.Request.Params["__EVENTTARGET"].ToString().ToLower().Contains("btncancemodal"))
{
try
{
txtSearch.Text = string.Empty;
//lsvSearchResult.Items.Clear();
DataSet ds = null;
lsvSearchResult.DataSource = ds;
lsvSearchResult.DataBind();
}
catch (Exception)
{
// error
}
}
}
怎么样:
DataSource = null;
DataBind();
或:
lsvSearchResult.DataSource = null;
lsvSearchResult.Items.Clear();
if(Page.Request.Params["__EVENTTARGET"]!=null){if(Page.Request.Params["__EVENTTARGET"].ToString().ToLower().Contains("btncheck"){string[]arg=Page.Request.Params["__EVENTARGUMENT"].ToString().Split(',');lsvSearchResult.DataSource=null;lsvSearchResult.DataBind();if(Convert.ToString(arg[0])=="IDNO"){if(Convert.ToString(arg[1]).Trim()!="){lsvSearchResult.DataSource=GetStudents(arg[0],arg[1]);lsvSearchResult.DataBind();}}else if(Convert.ToString(arg[0])=="NAME"){lsvSearchResult.DataSource=GetStudents(arg[0],arg[1]);lsvSearchResult.DataBind();}}
//GetStudents(arg[0], arg[1]);
}
else if (Page.Request.Params["__EVENTTARGET"].ToString().ToLower().Contains("btncancemodal"))
{
try
{
txtSearch.Text = string.Empty;
//lsvSearchResult.Items.Clear();
DataSet ds = null;
lsvSearchResult.DataSource = ds;
lsvSearchResult.DataBind();
}
catch (Exception)
{
// error
}
}
}
我把If花括号放错了位置。无论如何,感谢您的评论