簡體   English   中英

在回發時丟失動態數據綁定

[英]Lose dynamic data binding on postback

我有一個在運行時填充的網絡數據網格(每次用戶單擊不同的按鈕時,它都會加載不同的信息)

問題是在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>

EnableDataViewState設置為 true,然后WebDataGrid數據將被序列化為ViewState並將通過PostBack持久化,而無需重新綁定網格。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM