.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

ต้องการใช้ใส่สี footer ของgridview รวบกวนพี่เป้ด้วยครับ Options · View
Basketman
Posted: Sunday, May 25, 2008 4:49:24 PM

Rank: มือเทพ
Groups: Member

Joined: 12/9/2007
Posts: 104
Location: THA

คือผมต้องการลงสีในในแถวสุดท้ายท้ายสุดของ gv ครับ เช่น ผมต้องการเน้นสีแดงที่แถวสุดท้ายที่ผมรวมยอดสุทธิครับ

คือไม่ทราบว่าต้องใช้eventอะไร ถ้ายังไงรบกวนขอตัวอย่างด้วยนะครับ ขอบคุณครับ



i wanna be da Developer man~!!!! how??
paedotnet
Posted: Monday, May 26, 2008 3:37:53 PM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 354
Location: bkk

ถ้าจะใส่สี ให้กับ แถวสุดท้าย ( Footer ) ใน GridView

สิ่งแรกคือต้องกำหนด properties ตรง ShowFooter ให้เป็น true ก่อน

ดังรูป

จากนั้นก็เขียนโค้ดดังนี้ ( ให้คลิกที่ Gridview แล้วเลือก event ที่ชื่อ RowDataBound 

 

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.BackColor = Color.Red;
            }
        }


[With great power comes great responsibility]
Basketman
Posted: Monday, May 26, 2008 4:26:34 PM

Rank: มือเทพ
Groups: Member

Joined: 12/9/2007
Posts: 104
Location: THA

ขอบคุณครับพี่เป้



i wanna be da Developer man~!!!! how??
Basketman
Posted: Tuesday, June 03, 2008 6:31:34 AM

Rank: มือเทพ
Groups: Member

Joined: 12/9/2007
Posts: 104
Location: THA

 

int i = 0;
    int TotalPrice = 0;
    float avgPrice = 0;
    protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            i += 1;
 
            TotalPrice+=
              Convert.ToDouble(DataBinder.Eval(e.Row.DataItem,"UnitPrice"));
        }
        e.Row.Attributes.Add
            ("OnMouseOver", "style.backgroundColor='Lime'");
 
        e.Row.Attributes.Add
            ("OnMouseOut", "style.backgroundColor='White'");
 
         if(e.Row.RowType==DataControlRowType.Footer)
        {
            avgPrice = TotalPrice /i;
 
            e.Row.Font.Bold = true;
            e.Row.Cells[0].Text = "ราคาสินค้าเฉลี่ย : ";
 
            e.Row.Cells[2].Text = avgPrice.ToString("#,##0.00");
            e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;
            e.Row.BackColor = Color.YellowGreen;
        }
 
    }

convertค่าไม่ได้ครับ แต่ให้เป็น int16แล้วได้แต่ไม่ได้ค่าตามต้องการคับรบกวรอาจารย์พี่เป้หรือคนอื่นๆด้วยนะครับ ขอบคุณครับ



i wanna be da Developer man~!!!! how??
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by