 |
|
สอบถามเกี่ยวกับการสร้าง ปุ่ม linkbutton ใน table ที่เป็น object หน่อยครับ |
|
 |
|
|
 |
 |
|
คือผมได้สร้างปุ่ม linkbutton ตามจำนวน table ที่ได้สร้างขึ้นมา
พอ run โปรแกรมแล้ว ผมได้ทำการ คลิ้กปุ่ม linkbutton หลังจากที่คลิ้กแล้ว โปรแกรมไม่เ้ข้าไปทำงานใน even ของ ปุ่มครับแนะนำที
ส่วนของการสร้างปุ่ม
Code (VB.NET)
IB = New LinkButton
IB.Text = count + 1
IB.CommandArgument = CStr(count + 1)
AddHandler IB.Click, AddressOf ButtonClick
datacell1_1.Controls.Add(IB)
ส่วนโค้ดเต็มๆ
Code (VB.NET)
Private Sub Show_Table(ByVal Query As String, ByVal Day As String, ByVal null_d As Integer, ByVal colorS As Integer)
'Day = CInt(Day) + null_d
Dim chk_end As String = Day
Day += 6
Dim dt As New DataTable()
Dim row As Integer = 0
Dim rows As Integer = 0
Dim count As Integer = 0
Dim chk As Integer = 0
Dim column As Integer
Dim chk_head As Integer = 0
dt = dbb.Query(Query)
'If gv.Rows.Count >= 1 Then
rows = Day \ 7
If rows = 4 Then
rows = 5
End If
While row <= rows
Dim tr As New TableRow()
While column < 7
Dim tcell As New TableCell()
Dim dataTable As New Table()
Dim datarow1 As New TableRow()
Dim datarow2 As New TableRow()
Dim datarow3 As New TableRow()
Dim datacell1_1 As New TableCell() 'เวลา
Dim datacell2_1 As New TableCell() 'วันที่
Dim datacell3_1 As New TableCell() 'part
If count < 7 And chk_head = 0 Then
dataTable.BorderStyle = WebControls.BorderStyle.Solid
dataTable.BorderWidth = Unit.Pixel(3)
If count = 0 Then
datacell1_1.Text = "จันทร์"
ElseIf count = 1 Then
datacell1_1.Text = "อังคาร"
ElseIf count = 2 Then
datacell1_1.Text = "พุธ"
ElseIf count = 3 Then
datacell1_1.Text = "พฤหัสบดี"
ElseIf count = 4 Then
datacell1_1.Text = "ศุกร์"
ElseIf count = 5 Then
datacell1_1.Text = "เสาร์"
ElseIf count = 6 Then
datacell1_1.Text = "อาทิตย์"
End If
datacell1_1.HorizontalAlign = HorizontalAlign.Center
dataTable.BorderColor = Drawing.Color.LightBlue
dataTable.BackColor = Drawing.Color.LightYellow
datarow1.Cells.Add(datacell1_1)
dataTable.Rows.Add(datarow1)
dataTable.Width = Unit.Parse("100%")
dataTable.Height = Unit.Parse("20px")
dataTable.Attributes.Add("style", "table-layout:fixed")
dataTable.Font.Name = "verdana"
tcell.Controls.Add(dataTable)
tr.Cells.Add(tcell)
ElseIf count < null_d And chk = 0 And chk_head <> 0 Then
dataTable.BorderStyle = WebControls.BorderStyle.Solid
dataTable.BorderWidth = Unit.Pixel(3)
dataTable.BorderColor = Drawing.Color.LightBlue
datarow1.Cells.Add(datacell1_1)
dataTable.Rows.Add(datarow1)
dataTable.Width = Unit.Parse("100%")
dataTable.Height = Unit.Parse("100px")
dataTable.Attributes.Add("style", "table-layout:fixed")
dataTable.Font.Name = "verdana"
tcell.Controls.Add(dataTable)
tr.Cells.Add(tcell)
Else
dataTable.BorderStyle = WebControls.BorderStyle.Solid
dataTable.BorderWidth = Unit.Pixel(3)
dataTable.BorderColor = Drawing.Color.LightBlue
If count = colorS - 1 Then
dataTable.BackColor = Drawing.Color.LightGray
Else
dataTable.BackColor = Drawing.Color.LightYellow
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''
' เริ่มต้นการสร้างปุ่ม linkbutton
IB = New LinkButton
IB.Text = count + 1
IB.CommandArgument = CStr(count + 1)
AddHandler IB.Click, AddressOf ButtonClick
datacell1_1.Controls.Add(IB)
'''''''''''''''''''''''''''''''''''''''''''''''
If Chk_date(dt, count + 1) = True Then
datacell2_1.Text = Search_val(dt.Rows(0)("numbill"))
datacell3_1.Text = Search_val(dt.Rows(1)("numbill"))
Else
datacell2_1.Text = Chk_workday(dt, count + 1)
End If
datarow1.Cells.Add(datacell1_1)
datarow2.Cells.Add(datacell2_1)
datarow3.Cells.Add(datacell3_1)
datarow1.Height = 34
datarow2.Height = 33
datarow3.Height = 33
dataTable.Rows.Add(datarow1)
dataTable.Rows.Add(datarow2)
dataTable.Rows.Add(datarow3)
dataTable.Width = Unit.Parse("100%")
dataTable.Height = Unit.Parse("100px")
dataTable.Attributes.Add("style", "table-layout:fixed")
dataTable.Font.Name = "verdana"
tcell.Controls.Add(dataTable)
tr.Cells.Add(tcell)
End If
System.Math.Max(System.Threading.Interlocked.Increment(count), count - 1)
System.Math.Max(System.Threading.Interlocked.Increment(column), column - 1)
If count = 7 And chk_head = 0 Then
chk_head = 1
count = 0
End If
If count = null_d And chk_head <> 0 Then
chk = 1
count = 0
null_d = 100
End If
If count = chk_end Then
column = 10
row = rows
End If
End While
Table1.Rows.Add(tr)
Table1.Attributes.Add("style", "table-layout:fixed")
'If Table1.Rows.Count > 0 Then
' Table1.Width = (100 * (Table1.Rows(0).Cells.Count))
' Table1.Height = (100 * (Table1.Rows.Count))
'End If
column = 0
System.Math.Max(System.Threading.Interlocked.Increment(row), row - 1)
End While
'End If
End Sub
ส่วนของ event จากการคลิ้กปุ่ม
Code (VB.NET)
Private Sub ButtonClick(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim lb As LinkButton = CType(sender, LinkButton)
'displayObjects(lb.CommandArgument)
End Sub
Tag : .NET, Web (ASP.NET), VB.NET
|
|
 |
 |
 |
 |
Date :
2011-08-22 17:58:47 |
By :
sodamax |
View :
1311 |
Reply :
12 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแล้วไม่เข้าอ่ะครับพี่วิน ^^
|
 |
 |
 |
 |
Date :
2011-08-22 18:15:39 |
By :
sodamax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ้าววันนั้นไม่ใช่ได้แล้วเหรอครับ 
|
 |
 |
 |
 |
Date :
2011-08-22 18:23:16 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับพี่วิน
แต่อันใหม่ที่เปลี่ยนมาใช้ linkbutton มันไม่ได้ครับ
|
 |
 |
 |
 |
Date :
2011-08-22 18:25:10 |
By :
sodamax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองใช้การ Debug ดูยังครับ ว่ามันเข้า Event หรือไม่ 
|
 |
 |
 |
 |
Date :
2011-08-22 18:38:39 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แนะนำทีครับพี่วิน เปลี่ยนมาใช้ linkbutton แล้วไม่ได้ครับ
กดปุ่มไปแล้วมันไม่ยอมเข้าไปทำ ใน
Code (VB.NET)
Private Sub ButtonClick(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim lb As LinkButton = CType(sender, LinkButton)
'displayObjects(lb.CommandArgument)
End Sub
|
 |
 |
 |
 |
Date :
2011-08-22 18:39:06 |
By :
sodamax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดีบัคแล้วครับ ไม่เข้าเลยครับ
|
 |
 |
 |
 |
Date :
2011-08-22 18:41:37 |
By :
sodamax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดียวกลับถึงบ้านประมาณ 3 ทุ่มจะช่วยดูให้น่ะครับ อย่าลืมทักมาน่ะครับ งานเข้าอีกแล้ว 
|
 |
 |
 |
 |
Date :
2011-08-22 18:55:09 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับพี่วิน 3 ทุ่มเด่ว pm ไปหาเลยครับ อิอิ
|
 |
 |
 |
 |
Date :
2011-08-22 18:59:39 |
By :
sodamax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดียวเขียนให้พรุ่งนี้ครับ จะกลับมาโพสให้ครับ 
|
 |
 |
 |
 |
Date :
2011-08-22 22:40:30 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับพี่วิน
|
 |
 |
 |
 |
Date :
2011-08-23 11:09:04 |
By :
sodamax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองแล้วครับพี่วิน
ถ้าเกิดว่าผมเอา code ไปทำใน page_load มันก็ปกติครับ
แต่ถ้า code ไปอยู่ใน ปุ่ม มันไม่ได้ครับ
ผมก็งงว่าเป็นอะไ่ร
|
 |
 |
 |
 |
Date :
2011-08-23 16:12:44 |
By :
sodamax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|