PC Review


Reply
Thread Tools Rate Thread

Displaying Fields in GridView

 
 
Chris McGrath
Guest
Posts: n/a
 
      24th May 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=
Guest
Posts: n/a
 
      24th May 2007
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
>
>

 
Reply With Quote
 
=?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=
Guest
Posts: n/a
 
      24th May 2007
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
>
>

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      24th May 2007
On May 24, 7:28 pm, Chris McGrath <mcgra...@gmail.com> 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


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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gridview not displaying data. Paul Microsoft ASP .NET 4 19th Jun 2008 03:53 PM
gridview not displaying data Jonathan Beckloff Microsoft Dot NET Framework 0 28th Jul 2007 10:29 PM
displaying data for GridView David C Microsoft ASP .NET 2 24th Jul 2007 06:20 AM
Gridview not displaying data - please help! Greg Lyles Microsoft ASP .NET 8 4th Dec 2006 07:27 PM
Displaying the default fields from a DataSet, to the GridView Paul Aspinall Microsoft ASP .NET 2 29th Nov 2005 08:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:24 AM.