2013-07-29 71 views
0

我有一個DataGridView綁定到Oracle數據庫並帶有一個複選框列。這個想法是,當我選擇一個複選框時,其餘的會自動取消選中,或者找到一種方法來驗證在按下「確認」按鈕時只有一個複選框被選中。我可以獲得複選框行的索引和值,但我無法將值設置爲複選框。當在vb.net中選擇一個複選框時,取消選中GridView中的所有複選框

這是我使用代碼得到

Private Function GetSelectedRow() As Integer() 
    Dim Array As Integer() = {0, 0} 
    Dim index As Integer 
    Dim id_propuesta As Integer 
    For i As Integer = 0 To GridView3.Rows.Count - 1 
     Dim cb As CheckBox = DirectCast(GridView3.Rows(i).Cells(0).FindControl("CheckBox1"), CheckBox) 
     If cb IsNot Nothing Then 
      If cb.Checked Then 
       Dim hf As HiddenField = DirectCast(GridView3.Rows(i).Cells(0).FindControl("HiddenField1"), HiddenField) 
       If hf IsNot Nothing Then 
        id_propuesta = hf.Value 
        index = i 
       End If 
       Exit For 
      End If 
     End If 
    Next 
    Array(0) = index 
    Array(1) = id_propuesta 

    Return Array 
End Function 

回答

0

爲什麼不組單選按鈕在組框?雖然這樣做會更好嗎? 這是什麼意思?Dim cb As CheckBox = DirectCast(GridView3.Rows(i).Cells(0).FindControl("CheckBox1"), CheckBox)?從datagrid單元格中提取數據並將其分配給複選框?



你可以使用radD.Text = dgData.Rows(tracker1).DataBoundItem("OptionD").ToString 其中tracker1是列索引和「OptionD」是列名,radA.text是在單選按鈕的文本。而dgData是datagrid視圖的名稱

相關問題