繁体   English   中英

如何从asp.net中的datagrid删除行

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM