开发者

Filter on dataset clears all bound controls

The following code works (rows are filtered by the select expression), but then all the controls in the datarepeater are empty. When set to .DefaultView all records return and all controls have their values.

       Private Sub CheckBox_FilterApplied_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox_FilterApplied.CheckedChanged
    If CheckBox_FilterApplied.Checked Then
        ' RichTextBox_Notes.DataBindings.Add("Text", dsTransactions.Tables("TransactionHeader"), "Note")
        DataRepeater_Transactions.DataSource开发者_运维知识库 = dsTransactions.Tables("TransactionHeader").Select("Applied = 0")

        DataRepeater_Transactions.Refresh()
    Else
        DataRepeater_Transactions.DataSource = dsTransactions.Tables("TransactionHeader").DefaultView

    End If
End Sub

Can't tell what is missing. Refresh is no help.


I think the problem because of the DataSource of the Textbox and Datasource of the DataRepeater.

I modified the code slightly, Please try it. Works for me.

Dim dt As New DataTable
dt.Columns.Add("Col1")
dt.Columns.Add("Col2")
dt.Columns.Add("Col3")


For index = 1 To 10
    Dim dr As DataRow = dt.NewRow()
    dr("Col1") = index.ToString()
    dr("Col2") = index.ToString()
    dr("Col3") = index.ToString()
    dt.Rows.Add(dr)
Next

Dim dv As DataView = New DataView(dt, "Col1 >= 8", "", DataViewRowState.CurrentRows)

TextBox1.DataBindings.Add(New Binding("Text", dv, "Col3"))
DataRepeater1.DataSource = dv

Hope it helps :)


The DefaultView property is typed as a DataView whose IEnumerable enumerates over a DataRowView array which enables you to use the standard binding syntax. However, the Select method returns an array of DataRow objects which cannot be bound in the same way. The simplest solution is to ensure you pass a DataView to the DataSource property.

If CheckBox_FilterApplied.Checked Then
    Dim dt As DataTable = dsTransactions.Tables("TransactionHeader")
    Dim dv As DataView = New DataView(dt, "Applied = 0", "", DataViewRowState.CurrentRows)
    DataRepeater_Transactions.DataSource = dv

Else
    DataRepeater_Transactions.DataSource = dsTransactions.Tables("TransactionHeader")

End If

Also note, that can bind directly to the DataTable and do not need to explicitly use the DefaultView property as it will be used by default.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜