473,671 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1202
Hi,
Check the first question in http://www.datagridgirl.com/faq.aspx.

"Dave" <da*********@ho tmail.com> wrote in message
news:O4******** ******@TK2MSFTN GP11.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.D ataRowView)Cont ainer.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.D ataRowView)Cont ainer.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.ItemTy pe == ListItemType.Al ternatingItem || e.Item.ItemType ==
ListItemType.It em) && 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
1193
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. (Prev/Next on top and pg numbers on bottom is not an option) Therefore I am attempting to create my own custom navigation where I am very close except for the rendering of the page number links after clicking on one of them. In other words, Initial page...
2
1571
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 number of rows, so that old rows are discarded in favor of new rows if the limit is reached. My use case is very similar to that of the SQL Profiler GUI - I'm going to be receiving a large amount of data from a server that I want to display....
0
1616
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 using the example of CUSTOM PAGING on a DataGrid on this page: http://www.dotnetjunkies.com/Tutorial/EA868776-D71E-448A-BC23-B64B871F967F.dcik and im trying to add extra functionality in the DataGrid Paging - Custom Paging example. I'm able to get...
2
2743
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. The problem is the article is in VisualBasic. I already get the collection to be recognized as a Data Source by the IDE. It populated the DataGrid correctly from the fields on the items object of the collection, but I can't get the DataGrid to...
2
3186
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp The problem I am having is that the data in the custom datagridcolumn is not saved to viewstate and after postback, the column does not contain data.
4
4373
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 event arguments has no values. Is there any way to access and manipulate the row contents in this case ? Thanks in advance for any insigts in to this. -Souri
7
3339
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, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question, Ive implemented the drop down menu as a drop down list instead. Ive got all this working at this...
2
2433
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 fine. However, when attempting to assing default values as designtime in the propertygrid, nothing is working on the class object. I know that I am doing it wrong, any ideas what it is? Thanks in advance
1
1440
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 *OK' in the confirm box, he is taken to the next page. If he clicks *Cancel* in the confirm box, he stays on that page itself. I have a Web Form which houses a DataGrid. To edit the data in the DataGrid, I am using <asp:EditCommandColumn/>. To...
0
8478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8919
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8670
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7439
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6230
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2813
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.