Markup:
<asp:GridView ID="GridView1" runat="Server">
<Columns>
<asp:BoundField DataField="status_column" HeaderText="Status" />
<asp:BoundField ...
<asp:BoundField ...
</Columns>
</asp:GridView>
Code:
GridView1.DataSource = _dataSet
DataBind()
The values stored in my database are integers, 1 – 9. Each value has an associated string value that I want displayed in my GridView. Ex: 1 = “Active”; 2 = “On Hold”; etc. How would I filter the incoming data so I can display the associated String value instead of the Integers from my table?
You have two options:
containt a column for the string
representation of the data you
want to show.
containing a Label. Subscribe to the
OnRowDataBound Event of the
GridView, and get that Label with
e.Row.FindControl(“LabelID”), cast
the e.Row.DataItem to your DataRow,
and assign the string representation
of your integer value there.
I would advise against the solution posted by anishmarokey, because the query is not the correct place for this. Think a little big bigger, about localization for instance. Wouldn’t work with that solution, but with both of my suggested solutions.
Edit1:
Similiar answeres from me regarding the OnRowDataBound Event. If these don’t help you, I’m afraid you need to use google to find more examples:
Programmatically access GridView columns and manipulate
Custom GridView delete button
How to bind a complex dictionary to a Gridview in asp.net?
Edit2:
I’ve written an article that elaborates this topic further: http://www.tomot.de/en-us/article/7/asp.net/gridview-overview-of-different-ways-to-bind-data-to-columns