代码
1 // <summary>
2 /// 建立DataGrid的綁定處理方法
3 /// </summary>
4 /// <param name="sender"></param>
5 /// <param name="e"></param>
6 public void grdlist_ItemDataBound(object sender, DataGridItemEventArgs e)
7 {
8 if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
9 {
10 e.Item.Cells[0].Text = Convert.ToString(e.Item.ItemIndex + 1);
11 e.Item.Cells[2].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDCODE"));
12 e.Item.Cells[3].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDNAME"));
13 e.Item.Cells[4].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "CITYNAME"));
14 e.Item.Cells[5].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "TOWNNAME"));
15 e.Item.Cells[6].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDQTY"));
16 e.Item.Cells[7].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDUNIT"));
17 e.Item.Cells[8].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDTYPE"));
18 e.Item.Cells[9].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "TRANDATE"));
19 e.Item.Cells[10].Text = Left(DataBinder.Eval(e.Item.DataItem, "NOTE").ToString(), 15);
20
21 //添加title
22 e.Item.Cells[10].Attributes.Add("title", Convert.ToString(DataBinder.Eval(e.Item.DataItem, "NOTE")));
23 //雙擊後將資料帶入控件
24 e.Item.Attributes.Add("onclick", "javascript:document.all.hid_Land.value='" + Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDCODE")) + "';");
25
26 //改變GRID字體顏色
27 e.Row.Cells[i].ForeColor = System.Drawing.Color.Red;
28
29 //當鼠標接近grid時激發的事件
30 e.Item.Attributes.Add("onmouseover", "javascript:this.style.cursor='hand';");//鼠標接近時變為小手
31 e.Item.Attributes.Add("onmouseout", "javascript:this.style.cursor='';");//鼠標離開時恢復原狀
32 e.Item.Attributes.Add("onmousedown", "javascript:this.style.currentcolorbk=this.style.backgroundColor,this.style.currentcolorft=this.style.color;this.style.backgroundColor='#C0FFC0',this.style.color='Blue'");//鼠標點下時改變grid中選中行的顏色
33 e.Item.Attributes.Add("onmouseup", "javascript:this.style.cursor='',this.style.backgroundColor=this.style.currentcolorbk,this.style.color=this.style.currentcolorft");//恢復顏色
34 }
35
2 /// 建立DataGrid的綁定處理方法
3 /// </summary>
4 /// <param name="sender"></param>
5 /// <param name="e"></param>
6 public void grdlist_ItemDataBound(object sender, DataGridItemEventArgs e)
7 {
8 if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
9 {
10 e.Item.Cells[0].Text = Convert.ToString(e.Item.ItemIndex + 1);
11 e.Item.Cells[2].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDCODE"));
12 e.Item.Cells[3].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDNAME"));
13 e.Item.Cells[4].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "CITYNAME"));
14 e.Item.Cells[5].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "TOWNNAME"));
15 e.Item.Cells[6].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDQTY"));
16 e.Item.Cells[7].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDUNIT"));
17 e.Item.Cells[8].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDTYPE"));
18 e.Item.Cells[9].Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "TRANDATE"));
19 e.Item.Cells[10].Text = Left(DataBinder.Eval(e.Item.DataItem, "NOTE").ToString(), 15);
20
21 //添加title
22 e.Item.Cells[10].Attributes.Add("title", Convert.ToString(DataBinder.Eval(e.Item.DataItem, "NOTE")));
23 //雙擊後將資料帶入控件
24 e.Item.Attributes.Add("onclick", "javascript:document.all.hid_Land.value='" + Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LANDCODE")) + "';");
25
26 //改變GRID字體顏色
27 e.Row.Cells[i].ForeColor = System.Drawing.Color.Red;
28
29 //當鼠標接近grid時激發的事件
30 e.Item.Attributes.Add("onmouseover", "javascript:this.style.cursor='hand';");//鼠標接近時變為小手
31 e.Item.Attributes.Add("onmouseout", "javascript:this.style.cursor='';");//鼠標離開時恢復原狀
32 e.Item.Attributes.Add("onmousedown", "javascript:this.style.currentcolorbk=this.style.backgroundColor,this.style.currentcolorft=this.style.color;this.style.backgroundColor='#C0FFC0',this.style.color='Blue'");//鼠標點下時改變grid中選中行的顏色
33 e.Item.Attributes.Add("onmouseup", "javascript:this.style.cursor='',this.style.backgroundColor=this.style.currentcolorbk,this.style.color=this.style.currentcolorft");//恢復顏色
34 }
35
