473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Format DataGrid/View

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
2 1165
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
This works great. Thanks a bunch Bryan.

Feb 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
0
by: Albert Valls Rovira | last post by:
Hello all... I have a DataSet with two DataTables within (for example...) Table 1: Name Surnames CountryID Table 2: id CountryName I have created a relation between both tables (Table...
1
by: J.B | last post by:
I have a datagrid that will display different datasets, (it runs different sprocs based on a value in the querystring) but it will always return 6 columns. The 5th and 6th columns are always Date...
10
by: ruca | last post by:
Hi I want to format some columns of my DataGrid control. Example, one of my fields of DataSet is a DATE field and in BD he is Ok, but when I show him in datagrid he comes with hours too. I...
6
by: Hutty | last post by:
I've looked around and have yet to find anything that would answer my question regarding formating a column in a datagrid. My grid looks like this as far as data" AMHQCON|51300.01|-3147 The...
2
by: simonyong | last post by:
hello, anyone.. im newbie to asp.net my problem is : My task is related to view all data from a table called "employee " i had create a datagrid where called data from database and...
3
by: simonyong | last post by:
Im a newbie to asp.net, i hav a bit dilemma when thinking about how i should let it work.. My task as below: My task is related to view all data from a table called "employee " i had create a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.