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

Bind text to Gridview according to data

Hi to all,
I need to bind 'yes or no' in a grid view column according to status which is boolean.
I am Binding Status field directly to grid view column using this code
'<%#Eval("Status").ToString() %>' . But i want to bind yes if Status ='true' else No . how to do this, any help?
May 22 '07 #1
6 5623
you can do so by two ways.......

while getting the data from the database itself u can put case statement and get the data in yes/no format

or

loop through the gridview rows set the values yes/no for that column by checking true/false
May 22 '07 #2
you can do so by two ways.......

while getting the data from the database itself u can put case statement and get the data in yes/no format

or

loop through the gridview rows set the values yes/no for that column by checking true/false
Thanks Leela, Can you tell me the code for the second method i.e looping each gridview row.
May 22 '07 #3
you can do so by two ways.......

while getting the data from the database itself u can put case statement and get the data in yes/no format

or

loop through the gridview rows set the values yes/no for that column by checking true/false
Thanks Leela, Can you tell me the code for the second method of looping thro' rows
May 22 '07 #4
gomzi
304 100+
Hi to all,
I need to bind 'yes or no' in a grid view column according to status which is boolean.
I am Binding Status field directly to grid view column using this code
'<%#Eval("Status").ToString() %>' . But i want to bind yes if Status ='true' else No . how to do this, any help?
You can try this,
<%# iff(DataBinder.Eval(Container.DataItem("Status")). ToString().Equals("true"),"yes","no") %>

OR

As Leela mentioned,

Once you have taken the data in a dataset, you can add another column to the dataset, loop through the original dataset and add appropriate value for the new column.
May 22 '07 #5
Thanks Leela, Can you tell me the code for the second method of looping thro' rows
foreach(GridViewRow row in grd.Rows)
{

}
May 25 '07 #6
prabunewindia
199 100+
you can write one method in your code behind

public string getYesNo()
{
string Status="';
// code to get that status bool
if(status==true)
{
Status="Yes";
}
else
{
Status="No";
}
}

you should pass one parameter according your DataKeyfiled like below

public string getYesNo(string primaryKey)


and then call this in your gridview field text property

Text=<% # getYesNo(withparameter) %>
Prabu
May 25 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: COHENMARVIN | last post by:
I'm leafing through a big book on asp.net, and I don't see any way to the following: 1. bind values and text to a dropdown 2. Also make the first line of the dropdown say something different. For...
1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView on an Aspx page. I need my GridView to have three columns: Name , City and Photo I want to declare the data in my Aspx.Vb code and bind it to my GridView. I...
4
by: Dabbler | last post by:
I have two tables I'm editing in a Gridview. The VANS table contains a key to the other LESSOR table. I would like to use a dropdown list to select the LessorId value while displaying the Lessor...
2
by: Henry Lee | last post by:
hi, In ASP 2.0 , using datasource object with Gridview databind feature is really easy to show records from database. However , I want to do the samething but using textbox object because there...
0
by: teclioness | last post by:
Hi, I am using gridview for the user to update rows. In a row, there sre two columns, which need to be updated. When the gridview is to be shown, the row should show the values from database....
0
by: GMartin | last post by:
I have a pop-up form with a three columned Grid that has checkboxes in a Template Column in the first/left-most column. (The form is to allow users to select "Members" of a group, where they check...
1
by: weird0 | last post by:
I have created a GridView and dynamically added data to it by creating a DataTable(as advised) and bound it with a reader. Then, assigned the DataSource of GridView to DataTable. But even that aint...
3
by: Steve Kershaw | last post by:
Hi, I need a way to bind a DirectoryInfo array to a GridView without any errors. The code I'm using to create the DirectoryInfo array is: // Define the current directory DirectoryInfo dir...
1
by: dhamo | last post by:
How to bind checkbox with gridview in asp.net 2.0 I take a gridview control and bind data dynamicaly using code.I taken backend tool as a Ms Access and now I want to add new column with checkbox...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
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,...

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.