Question : Gridview label text changing from dataset population

I have a gridview that displays a lable from a database field.  The gridview is populated by a dataset but there is a value that will be returned occasionally that I don't want to display - I want to catch it in an if statement and manually change it to something else.  I don't know how to find that specific record as it comes up and target that row of the gridview to find that label and change the value - hopefully that makes sense and someone will know how to do that.

Answer : Gridview label text changing from dataset population

This is a quick example of the kind of thing you would need to do (obviously you need to change the text values and also the column index to match your own data):

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // check we are dealing with a data row
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // retrieve the data associated with the row
                System.Data.DataRowView row = e.Row.DataItem as System.Data.DataRowView;
                if (row != null)
                {
                    // check the value of the second field 
                    if (row[1].ToString() == "Wibble")
                    {
                        // we don't like it so change the value displayed to something else 
                        e.Row.Cells[1].Text = "Something Else";
                    }
                }
            }
        }
Random Solutions  
 
programming4us programming4us