Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. display a string in GridView istead of DB value

display a string in GridView istead of DB value

Scheduled Pinned Locked Moved ASP.NET
databasequestionhelptutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mustafa bulan
    wrote on last edited by
    #1

    Hi I have a probably quite easy question but which drives me crazy! I am using a Gridview in my web page. I bind with a sqldatasource and gridview displays all data correctly. But i want gridview to display an another string instead of the data in database. For example : There is a field named "isexists" in my table having 1 or 0 data. But on the web page , i want to show that column data as "YES" (instead of 1) and "NO" (instead of 0) in gridview. Could you please help me about this? Thanks and Regards mcbulan

    N 1 Reply Last reply
    0
    • M mustafa bulan

      Hi I have a probably quite easy question but which drives me crazy! I am using a Gridview in my web page. I bind with a sqldatasource and gridview displays all data correctly. But i want gridview to display an another string instead of the data in database. For example : There is a field named "isexists" in my table having 1 or 0 data. But on the web page , i want to show that column data as "YES" (instead of 1) and "NO" (instead of 0) in gridview. Could you please help me about this? Thanks and Regards mcbulan

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      mustafa bulan wrote:

      But on the web page , i want to show that column data as "YES" (instead of 1) and "NO" (instead of 0) in gridview.

      Either you can do this in the query or in row_databound event of GridView. In this event check the value, if value is 0 set the cells text as "NO" else "YES".

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

      M N 2 Replies Last reply
      0
      • N N a v a n e e t h

        mustafa bulan wrote:

        But on the web page , i want to show that column data as "YES" (instead of 1) and "NO" (instead of 0) in gridview.

        Either you can do this in the query or in row_databound event of GridView. In this event check the value, if value is 0 set the cells text as "NO" else "YES".

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        M Offline
        M Offline
        mustafa bulan
        wrote on last edited by
        #3

        thankx for your reply.:rose: but how i check the current value at that record? i need to know some codes like : // rowdatabound event if gridview1.rows(?).cells(??).text = "1" then gridview1.rows(?).cells(??).text = "YES" else gridview1.rows(?).cells(??).text = "NO" :^)

        A 1 Reply Last reply
        0
        • N N a v a n e e t h

          mustafa bulan wrote:

          But on the web page , i want to show that column data as "YES" (instead of 1) and "NO" (instead of 0) in gridview.

          Either you can do this in the query or in row_databound event of GridView. In this event check the value, if value is 0 set the cells text as "NO" else "YES".

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

          N Offline
          N Offline
          Neophyte30
          wrote on last edited by
          #4

          I have been doing similar checks using functions and the Eval keyword... i.e.

          ...Text='<%# ACunningFunction(Eval("db_field_name")) %>'

          Which would require something like:

          protected string ACunningFunction(object db_field)
          {
          //Check your db_field here and return an appropriate string
          }

          Are there any performance implications in doing it this way?

          N 1 Reply Last reply
          0
          • N Neophyte30

            I have been doing similar checks using functions and the Eval keyword... i.e.

            ...Text='<%# ACunningFunction(Eval("db_field_name")) %>'

            Which would require something like:

            protected string ACunningFunction(object db_field)
            {
            //Check your db_field here and return an appropriate string
            }

            Are there any performance implications in doing it this way?

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            This is a fair approach and I don't think about any performance issues.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

            1 Reply Last reply
            0
            • M mustafa bulan

              thankx for your reply.:rose: but how i check the current value at that record? i need to know some codes like : // rowdatabound event if gridview1.rows(?).cells(??).text = "1" then gridview1.rows(?).cells(??).text = "YES" else gridview1.rows(?).cells(??).text = "NO" :^)

              A Offline
              A Offline
              Akhilesh Yadav
              wrote on last edited by
              #6

              RowDatabound has two arguments object and events e you can go by e.cells("").value

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups