OnRowDataBound question

Discussion in 'ASP .Net' started by =?Utf-8?B?QWNvbnF1aWph?=, Aug 31, 2006.

  1. Hello,
    I have run into an issue when using the OnRowDataBound event to apply
    conditional formatting to a row. I need to check a specific column to see if
    the value from the database is null. Without conditional formatting the page
    just shows empty text in the table when the database column is null. I
    figured the text value would be equivalent to "" but that doesn't work. Here
    is a code snippet:

    Protected Sub Grid_Databound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
    If e.Row.Cells(10).Text = "" Then e.Row.Cells(10).Text = "blank"
    End If
    End Sub

    This does not work - the text on the page always displays empty, it never
    shows "blank". Am I missing something obvious? Is there a way to do this
    using code similar to what I have above, or do I need to use a template
    column along with a label control?

    Thanks,
    John
    =?Utf-8?B?QWNvbnF1aWph?=, Aug 31, 2006
    #1
    1. Advertising

  2. John,

    Why don't you set a breakpoint and check the value of the Text property?

    Likely, an empty cell is rendered with a non-breaking space character. You
    can either check on it, or try to trim it.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Aconquija" <> wrote in message
    news:...
    > Hello,
    > I have run into an issue when using the OnRowDataBound event to apply
    > conditional formatting to a row. I need to check a specific column to see
    > if
    > the value from the database is null. Without conditional formatting the
    > page
    > just shows empty text in the table when the database column is null. I
    > figured the text value would be equivalent to "" but that doesn't work.
    > Here
    > is a code snippet:
    >
    > Protected Sub Grid_Databound(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewRowEventArgs)
    > If e.Row.RowType = DataControlRowType.DataRow Then
    > If e.Row.Cells(10).Text = "" Then e.Row.Cells(10).Text =
    > "blank"
    > End If
    > End Sub
    >
    > This does not work - the text on the page always displays empty, it never
    > shows "blank". Am I missing something obvious? Is there a way to do this
    > using code similar to what I have above, or do I need to use a template
    > column along with a label control?
    >
    > Thanks,
    > John
    Eliyahu Goldin, Aug 31, 2006
    #2
    1. Advertising

  3. Thanks for the suggestion. I had actually tried something similar, and was
    confused because I was seeing a whitespace as the value. But your suggestions
    gave me an idea - I checked for a text value of in my code and it worked:

    If e.Row.Cells(10).Text = " " Then e.Row.Cells(10).Text = "blank"

    So I guess that the text value is of the row is the value that gets passed
    into the HTML code between the <td> tags, and isn't representative of the
    actual null value in the dataset cell.

    Am I on the right track?
    Thanks,
    John

    "Eliyahu Goldin" wrote:

    > John,
    >
    > Why don't you set a breakpoint and check the value of the Text property?
    >
    > Likely, an empty cell is rendered with a non-breaking space character. You
    > can either check on it, or try to trim it.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    >
    > "Aconquija" <> wrote in message
    > news:...
    > > Hello,
    > > I have run into an issue when using the OnRowDataBound event to apply
    > > conditional formatting to a row. I need to check a specific column to see
    > > if
    > > the value from the database is null. Without conditional formatting the
    > > page
    > > just shows empty text in the table when the database column is null. I
    > > figured the text value would be equivalent to "" but that doesn't work.
    > > Here
    > > is a code snippet:
    > >
    > > Protected Sub Grid_Databound(ByVal sender As Object, ByVal e As
    > > System.Web.UI.WebControls.GridViewRowEventArgs)
    > > If e.Row.RowType = DataControlRowType.DataRow Then
    > > If e.Row.Cells(10).Text = "" Then e.Row.Cells(10).Text =
    > > "blank"
    > > End If
    > > End Sub
    > >
    > > This does not work - the text on the page always displays empty, it never
    > > shows "blank". Am I missing something obvious? Is there a way to do this
    > > using code similar to what I have above, or do I need to use a template
    > > column along with a label control?
    > >
    > > Thanks,
    > > John

    >
    >
    >
    =?Utf-8?B?QWNvbnF1aWph?=, Aug 31, 2006
    #3
  4. =?Utf-8?B?QWNvbnF1aWph?=

    dust&bytes

    Joined:
    May 27, 2010
    Messages:
    1
    you can use the HTML Name as follows:

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

    If e.Row.RowType = DataControlRowType.DataRow Then

    If e.Row.Cells(10).Text = "&nbsp;" Then
    e.Row.Cells(10).Text = "blank"
    End If

    End If

    End Sub
    dust&bytes, May 27, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    578
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    639
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    933
    Scott Allen
    Oct 6, 2005
  4. Elmo Watson

    Row Item in DataView - OnRowDatabound event

    Elmo Watson, Nov 9, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,015
    Alvin Bruney [MVP]
    Nov 11, 2006
  5. David Thielen

    HyperLinkField and OnRowDataBound

    David Thielen, Oct 30, 2006, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    337
    David Thielen
    Oct 31, 2006
Loading...

Share This Page