How can you replace a field containing a code with text in a DataGrid?
-
I am just getting started with DataGrids in .NET 2.0 and am trying to figure out how to do the following: I have a DataSource returning columns from a table. One of the fields contains a code. For example, the field is 1 character in size and contains 'A', 'E', 'L', or 'U'. These stand for "Active", "Expired", "Locked", and "Unknown", respectively. How do I get my datagrid to show the word instead of the code letter? I don't need a DropDownList in the DataGrid column since it isn't editable. I suppose I could use one if it's readonly, but that seems like overkill since all I need is the text. Thanks.
A severed foot is the ultimate stocking stuffer. - Mitch Hedberg
-
I am just getting started with DataGrids in .NET 2.0 and am trying to figure out how to do the following: I have a DataSource returning columns from a table. One of the fields contains a code. For example, the field is 1 character in size and contains 'A', 'E', 'L', or 'U'. These stand for "Active", "Expired", "Locked", and "Unknown", respectively. How do I get my datagrid to show the word instead of the code letter? I don't need a DropDownList in the DataGrid column since it isn't editable. I suppose I could use one if it's readonly, but that seems like overkill since all I need is the text. Thanks.
A severed foot is the ultimate stocking stuffer. - Mitch Hedberg
You could handle the
DataGrid.ItemDataBound
event and do something to replace the code with text. However it would be easier to do this in your database query, joining your main table to a lookup table that contains the code descriptions and returning the description instead of the code.Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush
-
I am just getting started with DataGrids in .NET 2.0 and am trying to figure out how to do the following: I have a DataSource returning columns from a table. One of the fields contains a code. For example, the field is 1 character in size and contains 'A', 'E', 'L', or 'U'. These stand for "Active", "Expired", "Locked", and "Unknown", respectively. How do I get my datagrid to show the word instead of the code letter? I don't need a DropDownList in the DataGrid column since it isn't editable. I suppose I could use one if it's readonly, but that seems like overkill since all I need is the text. Thanks.
A severed foot is the ultimate stocking stuffer. - Mitch Hedberg
the follow is my way to solve it. i can code a public method in the cs code.. public string getCompele(string strValue) { string strReturn = ""; switch (strValue) { case "A": strReturn = "Active"; break; case "B": strReturn = "Expired"; break; case "C": strReturn = "Locked"; break; case "D": strReturn = "Unknown"; break; } return strReturn; } in the aspx code, i can use the method to get what i want,like this. ]]>' style="width: 119px;" i don't sure if this way can help you.
Study...
-
the follow is my way to solve it. i can code a public method in the cs code.. public string getCompele(string strValue) { string strReturn = ""; switch (strValue) { case "A": strReturn = "Active"; break; case "B": strReturn = "Expired"; break; case "C": strReturn = "Locked"; break; case "D": strReturn = "Unknown"; break; } return strReturn; } in the aspx code, i can use the method to get what i want,like this. ]]>' style="width: 119px;" i don't sure if this way can help you.
Study...
Thanks for the reply to this one. I went with the other solution posted, but this helped me understand the binding mechanism a lot better. Up until now we've done everything programmatically here. Thanks.
A severed foot is the ultimate stocking stuffer. - Mitch Hedberg
-
You could handle the
DataGrid.ItemDataBound
event and do something to replace the code with text. However it would be easier to do this in your database query, joining your main table to a lookup table that contains the code descriptions and returning the description instead of the code.Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush
Thanks. I wasn't going to create a master table for code values but in the end that seems best. That way I can keep the program logic smaller and it helps document the whole code system too.
A severed foot is the ultimate stocking stuffer. - Mitch Hedberg