2014-04-01 99 views
0

在我的代碼如下,我的("OnClick")沒有射擊。有誰知道爲什麼?點擊事件沒有從後面的代碼發射

e.Row.Cells(1).Attributes("OnClick") = "window.location.href='MachineSweepLite.aspx?AreaID='" _ 
    + GridView1.DataKeys(e.Row.RowIndex).Values("ID").ToString() 



Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound 
    If e.Row.RowType = DataControlRowType.DataRow Then 
     e.Row.Cells(1).Attributes("onmouseover") = "this.style.cursor='hand';this.style.textDecoration='underline';" 
     e.Row.Cells(1).Attributes("onmouseout") = "this.style.textDecoration='none';" 
     Dim Index As Integer = e.Row.RowIndex 
     e.Row.Cells(1).Attributes("OnClick") = "window.location.href='MachineSweepLite.aspx?AreaID='" + GridView1.DataKeys(e.Row.RowIndex).Values("ID").ToString 
    End If 
End Sub 

上面編輯。

+0

你能改正你的代碼並完全發佈嗎? –

+0

我不明白你? – Kallumasaurus

+1

@Kallumasaurus在這裏發佈完整的代碼,不僅僅是一個屬性添加行。 –

回答

1

您的屬性的錯誤,因爲你是閉幕單引號後加入ID 的價值...

例如,如果ID爲12,則表示您將此內容發送給瀏覽器...

window.location.href='MachineSweepLite.aspx?AreaID='12 

請注意,12不是URL的一部分。

你應該有,而不是下面...

e.Row.Cells(1).Attributes("onclick") = 
    string.Format("window.location.href='MachineSweepLite.aspx?AreaID={0}';", 
    GridView1.DataKeys(e.Row.RowIndex).Values("ID").ToString()) 

另外請注意,由於.NET 4.0不必多行跨越時有_字符。

+0

我會放棄這一點,並就此回覆你。 – Kallumasaurus

+0

幹得好,先生,帽子給你。這已經解決了我最棘手的問題。 – Kallumasaurus

+0

太好了 - 很高興聽到這是一個簡單的修復。第二雙眼睛通常都是需要的:-) – freefaller

0
e.Row.Attributes("onClick") = "CallFunction('" & Convert.ToString(GridView1.DataKeys(e.Row.RowIndex).Values("ID")) & "');" 

JS代碼:

function CallFunction(val) 
{ 
    // do your login here 
} 
+0

我不需要爲此添加一個函數,使事情變得複雜。 – Kallumasaurus