| |

VerySource

 Forgot password?
 Register
Search
View: 2245|Reply: 12

How to specify the colors of the first few columns in the DataList?

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-11 13:00:01
| Show all posts |Read mode
As the title. [For example, the first three columns are red, and the latter are unchanged.]
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-15 17:09:01
| Show all posts
First 3 columns
DataList1_ItemDataBound
Write in event
 if (e.Item.ItemIndex == 0 || e.Item.ItemIndex == 1 || e.Item.ItemIndex == 2)
{


}
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-16 11:54:01
| Show all posts
DlTodayNews.Items [2] .ForeColor = System.Drawing.Color.Red;
Actually said that it exceeds the index. Mine is 10 columns.
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-16 14:54:01
| Show all posts
First 3 columns
DataList1_ItemDataBound
Write in event
 if (e.Item.ItemIndex == 0 || e.Item.ItemIndex == 1 || e.Item.ItemIndex == 2)
{
e.Item.Style.Remove ("background-color");
e.Item.Style.Add ("background-color", "red");
}
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-16 15:54:01
| Show all posts
if ((args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem)&&(e.Item.ItemIndex == 0 || e.Item.ItemIndex == 1 || e. Item.ItemIndex == 2))
{
e.Item.Style.Remove ("background-color");
e.Item.Style.Add ("background-color", "red");
}
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-16 16:27:01
| Show all posts
Khan, finally modify it:
First 3 columns
DataList1_ItemDataBound
Write in event
if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)&&(e.Item.ItemIndex == 0 || e.Item.ItemIndex == 1 || e. Item.ItemIndex == 2))
{
e.Item.Style.Remove ("background-color");
e.Item.Style.Add ("background-color", "red");
}
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-16 16:36:01
| Show all posts
Your name is written in
if (e.item.itemIndex> -1)
{
    if (e.Item.ItemIndex == 0 || e.Item.ItemIndex == 1 || e.Item.ItemIndex == 2)
    {


     }
}
It's okay inside
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-17 19:09:02
| Show all posts
to:zhouji700did not change color, sweat ~
To:heihaiThe judgment added in front should be redundant? It still reports an index.
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-18 01:00:01
| Show all posts
Oh, you are using a DataList, and the method I told you is for the DataGrid
Ha ha
You use:
if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)&&(e.Item.ItemIndex == 0 || e.Item.ItemIndex == 1 || e. Item.ItemIndex == 2))
{
e.Item.BackColor = System.Drawing.Color.Red;
}
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-18 01:36:01
| Show all posts
I have passed the test here. If you test OK, remember to post in time, huh, huh.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list