Groups > Databases > MySQL for ASP.NET > Re: Change returned values?




Change returned values?

Change returned values?
Wed, 27 Feb 2008 22:52:41 +000
If I have a query, something to the effect of:

 SELECT * FROM MyTable WHERE id=?id

id can be, 1, 2, 3, 4 which all correspond to some friendly name (me, my, him,
her).

Using a GridView, how can I take those values and return them as their friendly
names, instead of numerals?  Is my only choice doing an AS clause in SQL?  Is
there some way I can return it to a function in the asp.net code (using vb.net)
that can say

If id = 1 then

mytext.text = "me"

else

...etc.  (not being in front of the gridview, I'm not quite sure how to modify a
cell's text).

If the above can be done somehow, would it also be possible to do when you're
selecting from multiple columns in MySQL?  E.g.:

SELECT race,gender FROM MyTable where id=?id

and modify the return values in code for both 'race' and 'gender'?  I don't want
to modify anything SQL-side, even if it may be the best and easiest option
(since this is just a web front end to the back end and the back end works with
a fat client that would also have to be modified, which would not be easy/beyond
my skill).
Post Reply
Re: Change returned values?
Thu, 28 Feb 2008 01:07:29 +000
Yes, you can do it using OnRowDataBind event, 

Protected Sub GridView_RowDatabound(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 = "1" Then e.Row.Cells(10).Text =
"me" 
End If 
End Sub
Post Reply
about | contact