 |
|
ผมอยากทราบวิธีการทำ Condition Format ใน Grild View ผมใช้ VB เขียนนะครับ |
|
 |
|
|
 |
 |
|
gridview นี่เว็บหรือเปล่า
เพราะ win กับ web ทำไม่เหมือนกัน
|
 |
 |
 |
 |
Date :
2013-10-24 09:50:10 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บน Web ครับ
|
 |
 |
 |
 |
Date :
2013-10-24 10:02:31 |
By :
zozazozy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขั้นแรกไป handle event rowdatabound ของ gridview ก่อนเลย
เขียนสด
Protected Sub GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
GridView gv = DirectCast(sender, GridView)
' ทำ hilight เมื่อ mouve over
e.Row.Attributes.Add("onmouseover", "javascript:this.style.backgroundColor='#EFF3FB';");
e.Row.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor='#FFFFFF';");
' add style ตามเงื่อนไข
If e.Row.RowType == DataControlRowType.DataRow Then
Dim age As Integer: age = Convert.ToInt16(e.Row.Cells(2).Text)
Dim address As String: address = e.Row.Cells(4).Text
If age > 35 Then
e.Row.Cells(2).Style.Add(HtmlTextWriterStyle.Color, "Red")
End If
If address.Contains("กรุงเทพ") Then
e.Row.Cells(4).Style.Add(HtmlTextWriterStyle.Color, "Blue")
End If
End If
End Sub
|
 |
 |
 |
 |
Date :
2013-10-24 10:27:55 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Error ครับ
Input string was not in a correct format.
Dim age As Integer: age = Convert.ToInt16(e.Row.Cells(2).Text) ("ผมดูค่าใน e.Row.Cells(2).Text มันเหมือนเป็น Text เลยครับ มี "20" อยู่ด้วยครับ
ตอนนี้ได้แล้วครับ ต้องเอา Convert.ToInt16 ออกครับ ใส่ Dim age As Integer: age = e.Row.Cells(2).Text ได้แล้วครับขอบคุณครับ
แต่ติดปัญหาเรื่อง Mouse Over หลังจากออกแล้ว Format Grild veiw ขาวหมดเลยครับ
|
ประวัติการแก้ไข 2013-10-24 10:58:50
 |
 |
 |
 |
Date :
2013-10-24 10:53:45 |
By :
zozazozy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Protected Sub GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
' GridView gv = DirectCast(sender, GridView) <-- ดูแล้วไม่ได้ใช้
' ทำ hilight เมื่อ mouve over
e.Row.Attributes.Add("onmouseover", "javascript:this.style.backgroundColor='#EFF3FB';");
e.Row.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor='#FFFFFF';");
' add style ตามเงื่อนไข
If e.Row.RowType == DataControlRowType.DataRow Then
Dim address As String: address = e.Row.Cells(4).Text
If address.Contains("กรุงเทพ") Then
e.Row.Cells(4).Style.Add(HtmlTextWriterStyle.Color, "Blue")
End If
' ถ้าข้อมูลมันปกติมันไม่ error หรอก สงสัยทีค่าว่างใน cell
If Not String.IsNullOrEmpty(e.Row.Cells(2).Text) Then
Dim age As Integer: age = Convert.ToInt16(e.Row.Cells(2).Text)
If age > 35 Then
e.Row.Cells(2).Style.Add(HtmlTextWriterStyle.Color, "Red")
End If
End If
End If
End Sub
|
 |
 |
 |
 |
Date :
2013-10-24 11:02:36 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
ได้แล้วครับ
|
 |
 |
 |
 |
Date :
2013-10-24 11:25:40 |
By :
zozazozy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|