By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,341 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,341 IT Pros & Developers. It's quick & easy.

Format DataGrid/View

P: n/a
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.

Feb 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
bpd
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.

Feb 23 '07 #2

P: n/a
This works great. Thanks a bunch Bryan.

Feb 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.