

--鍵下GridView的編輯鍵時
Protected Sub GVQuery_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
'秀出該被編輯該行值
'Response.Write(e.NewEditIndex)
Dim strLabCompID As Label =
Me.GVQuery.Rows(e.NewEditIndex).FindControl("LabCompID")
Dim strLabEmpID As Label =
Me.GVQuery.Rows(e.NewEditIndex).FindControl("LabEmpID")
'利用function將要放入listbox的資料組好後
Dim strlistbox As String =
ChgClassKind("2", strLabCompID.Text, strLabEmpID.Text)
Dim strlistarray As String()
Dim strlistCKD As ListBox =
Me.GVQuery.Rows(e.NewEditIndex).FindControl("ListCKD")
Dim i As Integer
--先將ListBox的值清除
strlistCKD.Items.Clear()
--判斷是否有要放入ListBox的資料,有才執行
If Trim(strlistbox) "" Then
--是利用;來作為一筆資料,故要先將所有的資料拆成一筆一筆的
strlistarray = Split(strlistbox, ";")
--UBound(strlistarray)算出該陣列的最大值
For i = 0 To UBound(strlistarray)
strlistCKD.Items.Add(strlistarray(i))
Next
End If
--按下編輯後,設定游標停留的地方
Me.GVQuery.Rows(e.NewEditIndex).FindControl("TxtOnTheJobDate").Focus()
End Sub
----以下為在GridView中按下button後所會觸發的事件---------------------------------------------------
----加入鍵
Protected Sub ButAppend_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'找出執行的該行的row_index
Dim strAppend As Button = sender
Dim Row As GridViewRow = strappend.NamingContainer
'Response.Write(bb.RowIndex)
Dim strClassFlag As RadioButtonList =
GVQuery.Rows(Row.RowIndex).FindControl("RBClassFlag")
Dim strDPCKD As DropDownList =
GVQuery.Rows(Row.RowIndex).FindControl("DPCKD")
Dim strListCKD As ListBox =
GVQuery.Rows(Row.RowIndex).FindControl("ListCKD")
strListCKD.Items.Add(strClassFlag.SelectedValue & "-"
& strDPCKD.Items(strDPCKD.SelectedIndex).Value
& "-" & strDPCKD.Items(strDPCKD.SelectedIndex).Text)
End Sub
----移除鍵
Protected Sub ButRemove_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'找出執行的該行的row_index
Dim strAppend As Button = sender
Dim Row As GridViewRow = strAppend.NamingContainer
'Response.Write(bb.RowIndex)
Dim strListCKD As ListBox =
GVQuery.Rows(Row.RowIndex).FindControl("ListCKD")
strListCKD.Items.Remove(strListCKD.SelectedValue)
End Sub