On Feb 23, 12:27 pm, "Joel" <joelra...@gmail.comwrote:
I'm trying to format the data from our database query that is being
binded to a DataGrid. Basically an easy example to understand the
problem is a field in the database uses 1's and 0's to show true or
false but our user doesn't need to see this nor do they understand it
so if it equals 1 then show true etc.
Another issue is I would like to format a field into a hyperlink
based
off the database value. I've experimented with TemplateColumns but
haven't had much success. I also could do this before binding the
Data
after a sql query but I'm not sure the best way to go about that.
Thanks for the help.
Hyperlink NavigateURL field in a gridview example:
<asp:TemplateField HeaderText="History">
<ItemTemplate>
<asp:HyperLink ID="<your ID here>" runat="server"
NavigateUrl='<%#
Format_URL(DataBinder.Eval(Container, "DataItem.<your data field
here>" ).ToString(), "")
%>'>your text here</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
The dataitem field will be the field you want to drive the
value of the url.
In the code behind, create a public procedure to return a
string (the url). For example (c#)
public string Format_URL(string some_field)
{
string res = string.empty;
if (some_field.Trim().Length 0)
{
res = some_url;
}
else
{
res = some_other_url;
}
return res;
}
Formatting a datagrid field for true or false instead of 0 or 1 will
be similar
to the hyperlink example above.