我有一个通过 sqldatasource 从本地 sql db 填充的 gridview。
sqldatasource的select命令为:SelectCommand="SELECT * FROM [CERecord] ORDER BY [Priority]"
在我后面的代码中,我有一个单选按钮列表,其中显示所有记录、活动记录、已完成记录:
protected void rblShowRecords_SelectedIndexChanged(object sender, EventArgs e)
{
switch (rblShowRecords.SelectedValue)
{
case "Show Active/Completed":
CEDatabaseSource.SelectCommand = "SELECT * FROM [CERecord] ORDER BY [Priority]";
break;
case "Show Active":
CEDatabaseSource.SelectCommand = "SELECT * FROM [CERecord] WHERE [Completed]='false' ORDER BY [Priority]";
break;
case "Show Completed":
CEDatabaseSource.SelectCommand = "SELECT * FROM [CERecord] WHERE [Completed]='true' ORDER BY [Priority]";
break;
default:
break;
}
CEDatabaseSource.DataBind();
gvRecordList.DataBind();
}
当我在仅活动或仅完成模式下尝试更新行时,我遇到了一个奇怪的问题,即使我在上面的方法中设置了新命令,它似乎也只是开始显示所有行。
当您在gridview中单击一行上的更新时,它是否总是运行默认的选择命令:SelectCommand="SELECT * FROM [CERecord] ORDER BY [Priority]"
?