Displaying Fields in GridView

C

Chris McGrath

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
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top