[英]How to remove row from datagrid in asp.net
我有一個datagrid dgCompanies這樣聲明:
// bind the data to the datagrid
dgCompanies.PageSize = pageSize;
dgCompanies.DataSource = rdr;
然后,我需要檢查此datagrid中的記錄:
int j = 0;
foreach (DataGridItem item in dgCompanies.Items)
{
HtmlGenericControl name = (HtmlGenericControl)item.Cells[j].FindControl("SpanTitle");
string drstring = name.InnerHtml.Trim();
if (checkingfunction(drstring))
{
//do removing record from datagrid.
I tried this: item.Cells.Remove(item.Cells[j]); but the result still there, don't see anything removed!
}
j = j + 1;
}
dgCompanies.DataBind();
如果條件滿足,如何從datagrid dgCompanies
刪除該記錄?
我同意@Andrei,最好不要返回該數據。 否則,您將返回並瀏覽不必要的數據。 但是,如果在這種情況下您不能預先過濾數據,我想您可以在行中添加一個css類“ donotshow”(請參閱如何為GridView中的特定行指定CSS類? )。
然后用jquery使用
$('.donotshow').hide();
同樣,在這方面,您仍將所有HTML返回給瀏覽器,這樣將使頁面大小超出必要。 此外,如果使用此方法,則使用分頁可能會搞亂分頁(例如,如果顯示“第1-10行”,但隱藏了5行,則看起來會很愚蠢)。
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.