473,407 Members | 2,326 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,407 software developers and data experts.

View some custom text in DataGrid

Hello.
I have a boolean field in my database (true=1, false=0), nowwhen I bind data
to my DataGrid it shows me "1" or "0", but I want while displayng this data
show some ohter text, for example if field is 1 show "Active" and if 0
"Inactive"?
How can I do this?

Than You.
Nov 18 '05 #1
2 1189
Hi,
Check the first question in http://www.datagridgirl.com/faq.aspx.

"Dave" <da*********@hotmail.com> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
Hello.
I have a boolean field in my database (true=1, false=0), nowwhen I bind data
to my DataGrid it shows me "1" or "0", but I want while displayng this data
show some ohter text, for example if field is 1 show "Active" and if 0
"Inactive"?
How can I do this?

Than You.

Nov 18 '05 #2
There are 2 possible ways to do this stuff.

first:
on grid, you should convert your column to a template column. After that,
you go (from a right click on grid), in edit template of your column. In this
step you'll see there a label in itemtemplate. On label properties go to
databidings. On text "Bindable Property" you should write in "Custom Binding
Expresion" a code like this one

((System.Data.DataRowView)Container.DataItem)["Test"].ToString() == "1" ?
"Active" : "Inactive"

if you go to HTML mode you should see something like this
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%#
((System.Data.DataRowView)Container.DataItem)["Test"].ToString() == "1" ?
"Active" : "Inactive" %>'>
</asp:Label>
</ItemTemplate>
if is not exatly like this you should change the text to be somehow like
this.

the second way is a little bit complicated
you should write some code on grid event itemcreated. Also you should have
that column as a teampte column.
Soo the code should look like this :
if ((e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.Item) && e.Item.DataItem != null) {
Label b = e.Item.Cells[2].Controls[1] as Label;
int test = Convert.ToInt32(((DataRowView)e.Item.DataItem).Row["Test"]);
if(b != null){
b.Text = test == 1 ? "Active" : "Inactive";
}

Cheers HTH

"Dave" wrote:
Hello.
I have a boolean field in my database (true=1, false=0), nowwhen I bind data
to my DataGrid it shows me "1" or "0", but I want while displayng this data
show some ohter text, for example if field is 1 show "Active" and if 0
"Inactive"?
How can I do this?

Than You.

Nov 18 '05 #3

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

Similar topics

0
by: Mark | last post by:
I need some advice on how to acheive the desired result of my custom page link generation. The datagrid 'built-in' page navigation only allows either the 'Prev/Next' or the page numbers. ...
2
by: Chris Mullins | last post by:
I'm building a GUI that needs to be able to view a large amount of text arranged in rows. Large being anywhere from a few hundred lines through a few hundred thousand. I need a way to "cap" the max...
0
by: Stephen | last post by:
This is a real brain-teaser and i'd really appreciate it if someone can try and understand what im trying to do and give me a few pointers or ideas to help me work out my problem. Im basically...
2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
4
by: Souri Challa | last post by:
Hello All, When a datagrid in a web form is getting re populated from view state on post back, it is firing the datagrid Item Created event but the DataGridItem(e.Item.DataItem is null) in the...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
2
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
1
by: rn5a | last post by:
I have created a custom server control which is actually a Button clicking which prompts a user with a JavaScript confirm message asking him whether he would like to proceed or not. If he clicks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.