473,320 Members | 1,802 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,320 software developers and data experts.

Displaying Fields in GridView

Hello all,

I have a gridview that I would like to check a value for a datafield
and depending on that value, either display or not display another
datafield in the same row. I need to do this on the original
databinding of the grid.

Can someone point me in the right direction?

Thanks,
Chris

May 24 '07 #1
3 943
I do this often
1. i'd convert the columns you need to change into templates and named
labels
2. gvr is the current gridview row, szLBL is the id of the label to be
changed, szField is the name of the data field you are checking.

Public Function fn_returnLBLcolorForPosNeg(ByVal gvr As GridViewRow, ByVal
szLBL As String, ByVal szField As String) As Boolean

Dim lbl As Label = gvr.FindControl(szLBL)
If gvr.DataItem(szField) = "Positive" Then
lbl.ForeColor = Drawing.Color.DarkGreen
ElseIf gvr.DataItem(szField) = "Negative" Then
lbl.ForeColor = Drawing.Color.DarkRed
Else
lbl.ForeColor = Drawing.Color.DarkGray
End If
End Function

hope this helps
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
"Chris McGrath" wrote:
Hello all,

I have a gridview that I would like to check a value for a datafield
and depending on that value, either display or not display another
datafield in the same row. I need to do this on the original
databinding of the grid.

Can someone point me in the right direction?

Thanks,
Chris

May 24 '07 #2
sorry: You call this function in the row databound event......
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
"Chris McGrath" wrote:
Hello all,

I have a gridview that I would like to check a value for a datafield
and depending on that value, either display or not display another
datafield in the same row. I need to do this on the original
databinding of the grid.

Can someone point me in the right direction?

Thanks,
Chris

May 24 '07 #3
On May 24, 7:28 pm, Chris McGrath <mcgra...@gmail.comwrote:
Hello all,

I have a gridview that I would like to check a value for a datafield
and depending on that value, either display or not display another
datafield in the same row. I need to do this on the original
databinding of the grid.

Can someone point me in the right direction?

Thanks,
Chris
Hi Chris,

create a wrapper function

<GridView...
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# getValue(Eval("col1"))%>
</ItemTemplate>
</asp:TemplateField>

in the code-behind

protected string getValue(object v)
{
if((int) v == 1)
return "ok";
else
return "false";
}

Hope it helps

May 24 '07 #4

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

Similar topics

2
by: Paul Aspinall | last post by:
Hi I'm binding a DataSet, using the ObjectDataSource control, to a GridView I want the GridView to default to the columns returned in the DataSet, without having to specifically name them. ...
10
by: gnewsgroup | last post by:
I've googled and tried various approaches, but could not resolve this problem. The article at MSDN: Displaying Images in a GridView Column only presents a simple case where all data (including the...
4
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I get the error (the data source for the gridview does not have any properties from which do generate columns) I am binding the data as follows, errors out on the databind line. The...
1
by: readnlearn | last post by:
Hii, in my table I have fields like id1,title,description,category,posteddate..In my gridview I wish to display title,posteddate and category. I placed a hyperlink for title field. Now when I click...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.