2011-05-18 34 views
0

我想在gridview中使用另一行中的標籤,並在用戶單擊其自己的列中的按鈕時將其插入表中。在sqldatasource插入命令中使用gridview行控制

我的問題是,我不能讓bookno其中發現標籤設置爲@bookno在我的SqlDataSource

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
     Dim selectedRow As Button = DirectCast(sender, Button) 



     Dim bookno As Label = CType(selectedRow.FindControl("label1"), Label) 
     Dim why As TextBox = CType(selectedRow.FindControl("textbox2"), TextBox) 
     Dim yesint As Integer = 1 
     Dim sql As SqlDataSource = CType(selectedRow.FindControl("sqldatasource4"), SqlDataSource) 
     sql.InsertParameters.Add(bookno.Text, 0) 


     sql.Insert() 

    End Sub 
+0

您是否收到任何錯誤?而bookno.Text包含什麼?它是參數名還是值? – gbs 2011-05-18 19:35:34

回答

1

嘗試

Dim bookno As Label = CType(selectedRow.Parent.FindControl("label1"), Label) 

,看看你是否得到有效控制bookno。如果有效,請爲其他FindControl()來電執行相同操作。

+0

我所做的只是將sqldatasource複製到預訂模板字段中,將label1設置爲參數控制,並將數據源複製回我的outher templatefield,並且它工作得很好 – 2011-05-19 13:55:35