Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CSS
filename     path         Status
    -----------------------------
    1.txt      D:\JI\1.txt     E
    a.txt      D:\JI\a.txt     D
    b.txt      D:\JI\b.txt     E






C#
This is my datatable values.I want to bind this value to a gridview.Before that I want to remove / hide the the rows which having the status as 'D'.I used onRowdatabound event ,but its not working .please help

  dtTemSec = (DataTable)ViewState["SecDetails"];
 GridImport.DataSource = dtTemSec;
                GridImport.DataBind();
Posted
Updated 24-Jan-20 2:13am
Comments
Kornfeld Eliyahu Peter 30-Mar-15 2:23am    
Apply filter on data source...

BoundField


Something like below would work, if you have used BoundField.
C#
private void GridImport_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.Cells[2].Text.Equals("D"))
            e.Row.Visible = false;
    }
}

TemplateField


If the value is inside a TemplateField, then you need to find that control and then try to compare the text like... Suppose there is a TextBox inside TemplateField, where the value is fastened.
C#
private void GridImport_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        TextBox txtStatus = (TextBox)rw.FindControl("txStatus");
        
        if (txtStatus.Text.Equals("D"))
            e.Row.Visible = false;
}
 
Share this answer
 
XML
GridImport.DataSource = dtTemSec.AsEnumerable()
                                .Where(x => x.Field<string>("Status") != "D")
                                .CopyToDataTable();
GridImport.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900