在回发时丢失动态数据绑定

时间:2016-03-21 16:13:35

标签: asp.net vb.net infragistics webdatagrid

我有一个在运行时填充的webdata网格(每次用户点击不同的按钮时,它会加载不同的信息)

问题是在selected row change上,网格没有得到正确的行,因为它做了回发,并且删除了网格中的数据

Protected Sub grid_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebDataGrid1.Load
    If Not IsPostBack Then
        Me.WebDataGrid1.DataSource = Membership.FindUsersByName("A%")
        Me.WebDataGrid1.DataBind()
    End If
End Sub

Protected Sub WebDataGrid1_Selection_RowSelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebDataGrid1.RowSelectionChanged
     Dim thisrow = e.CurrentSelectedRows

End sub

thisrow始终等于Nothing

如何让databind()继续回发以便我可以访问所选行中的信息?

<ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="False" Width="750px" AltItemCssClass="AltRows" >
                    <Columns>
                        <ig:BoundDataField DataFieldName="UserName" DataType="System.String" Key="UserName">
                            <Header Text="User Name">
                            </Header>
                        </ig:BoundDataField>
                        <ig:BoundDataField DataFieldName="Email" Key="Email">
                            <Header Text="Email">
                            </Header>
                        </ig:BoundDataField>
                        <ig:BoundCheckBoxField DataFieldName="IsApproved" Key="IsApproved" Width="75px">
                            <Header Text="Approved">
                            </Header>
                        </ig:BoundCheckBoxField>
                        <ig:BoundCheckBoxField DataFieldName="IsLockedOut" Key="IsLockedOut" Width="100px">
                            <Header Text="Locked Out">
                            </Header>
                        </ig:BoundCheckBoxField>
                        <ig:BoundDataField DataFieldName="LastLoginDate" Key="LastLoginDate">
                            <Header Text="LastLoginDate">
                            </Header>
                        </ig:BoundDataField>
                    </Columns>
                    <Behaviors>
                        <ig:Selection CellClickAction="Row" CellSelectType="None" RowSelectType="Single">
                            <SelectionClientEvents RowSelectionChanged="WebDataGrid1_Selection_RowSelectionChanged" />
                            <AutoPostBackFlags RowSelectionChanged="True" />
                        </ig:Selection>
                    </Behaviors>
                </ig:WebDataGrid>

1 个答案:

答案 0 :(得分:1)

EnableDataViewState设置为true,然后WebDataGrid数据将序列化为ViewState,并且会在PostBack之后保留,而不会重新绑定网格。

<ig:WebDataGrid ID="WebDataGrid1" 
                runat="server" 
                AutoGenerateColumns="False" 
                Width="750px" 
                AltItemCssClass="AltRows"
                EnableDataViewState="True">
    ...
</ig:WebDataGrid>