Template column base on another column value

E

Esperanza

Hello .net expert,
I would like to change the color a a column "Name" base on the value of
another column "tel" . Is it possible ???

Thanks in advance !!
Esperanza


<ItemTemplate>
<b>
<%#CustomColorRow(DataBinder.Eval(Container.DataItem,"XTEL"))%>
</b>
</ItemTemplate>

'=============================================
public string CustomColorRow(object indiceAppel)
{
if (indiceAppel.Equals("5147426101"))

{
return "<span style=\"background-color:blue;\">" +indiceAppel +
"</span>";
}
else
{ return "<span style=\"background-color:white;\">" +indiceAppel +
"</span>";
}
}
 
E

Elton Wang

Yes.

In datagrid_ItemCreated

ListItemType itemType = e.Item.ItemType;

if (itemType == ListItemType.Header){
TableCell cell = e.Item.Cells(index1);
TableCell cell1 = e.Item.Cells(index2); //
column "tel"
if (cell1.Text.Equals("Something")){
cell.Text = ...;
cell.BackColor = Color.somecolor;
}
}

HTH,

Elton Wang
(e-mail address removed)
 
E

Esperanza

It seems to generate a problem
Error message :
'System.Web.UI.WebControls.TableRow.Cells' denotes a 'property' where a
'method' was expected

am I missing something ?



private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if (itemType == ListItemType.Header)
{
TableCell cell = e.Item.Cells(6); //Client
TableCell cell1 = e.Item.Cells(9);//Phone
if (cell1.Text.Equals("4442221212"))
{
cell.BackColor = Color.LightBlue;
}
}

}
 
E

Esperanza

Me again,
Ok, now I can compile without problem,
I'm going step by step into the code and I realized that
it compared the header value instead of the value of the cell.
cell1.Text = "Phone" so
"Phone" never equal 514-222-1111

so the phone number backcolor never changed color.

Thanks in advance !!
Esperanza


'==============================
ListItemType itemType = e.Item.ItemType;
if (itemType == ListItemType.Header)
{
TableCell cell = e.Item.Cells[6]; //Client
TableCell cell1 = e.Item.Cells[9];//Phone
if (cell1.Text.Equals(514-222-1111))
{
cell.BackColor = Color.LightBlue;
}
}



"Elton Wang" <[email protected]> a écrit dans le message
de Use
e.Item.Cells[6]/[9] and so on.

HTH

Elton Wang
 
E

Elton Wang

Yes. The code sample is only for Header. If you want for
items, you should do something like

if(itemType != ListItemType.Header && itemType !=
ListItemType.Pager && itemType != ListItemType.Footer &&
itemType != ListItemType.Seperator){
// code here
}

HTH,

Elton
-----Original Message-----
Me again,
Ok, now I can compile without problem,
I'm going step by step into the code and I realized that
it compared the header value instead of the value of the cell.
cell1.Text = "Phone" so
"Phone" never equal 514-222-1111

so the phone number backcolor never changed color.

Thanks in advance !!
Esperanza


'==============================
ListItemType itemType = e.Item.ItemType;
if (itemType == ListItemType.Header)
{
TableCell cell = e.Item.Cells[6]; //Client
TableCell cell1 = e.Item.Cells[9];//Phone
if (cell1.Text.Equals(514-222-1111))
{
cell.BackColor = Color.LightBlue;
}
}



"Elton Wang" <[email protected]> a écrit dans le message
de Use
e.Item.Cells[6]/[9] and so on.

HTH

Elton Wang
-----Original Message-----
It seems to generate a problem
Error message :
'System.Web.UI.WebControls.TableRow.Cells' denotes a 'property' where a
'method' was expected

am I missing something ?



private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if (itemType == ListItemType.Header)
{
TableCell cell = e.Item.Cells(6); //Client
TableCell cell1 = e.Item.Cells(9);//Phone
if (cell1.Text.Equals("4442221212"))
{
cell.BackColor = Color.LightBlue;
}
}

}
"Elton Wang" <[email protected]> a
écrit
dans le message


.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top