简体   繁体   中英

Lose dynamic data binding on postback

I have a webdata grid that is being populated during runtime (each time a user clicks on a different button, it loads different information)

The problem is that on selected row change the grid is not getting the right row because it does a post back, and gets rid of the data in the grid

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 always equals Nothing

How can I get the databind() to persist over postback so that I can access the information in the selected row?

<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>

Set EnableDataViewState to true and then the WebDataGrid data will be serialized to ViewState and will persist through PostBack without rebinding the grid.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM