views:

89

answers:

0

I have a ListView that is databound thru DataSource of type typed dataset table.

    private void LoadTrusts(int? clientId, int? imageId)
    {
        TrustDataSource = GetTrusts(clientId, imageId);
        _TrustListView.DataSource = TrustDataSource;
        _TrustListView.DataBind();
    }

Where TrustDataSource is saved to ViewState.

    protected TrustDataSet.TrustsDataTable TrustDataSource
    {
        get
        {
            if (_TrustDataSource == null)
                _TrustDataSource = ViewState["TrustDataSource"] as TrustDataSet.TrustsDataTable;
            return _TrustDataSource;
        }
        set
        {
            _TrustDataSource = value;
            ViewState["TrustDataSource"] = value;
        }
    }

After making changes on the bound (through Bind(…)) fields on ListView, Is there a way to get only changed subject of rows and save them as whole through data adapter?

For some reason, _TrustListView.DataSource is null after postback and this would not work.

    private void SaveTrusts()
    {
        //new TrustWriter(GetConnectionString()).SaveTrusts(TrustDataSource);
        // At this point, "TrustDataSource" doesn't contain modified value on the ListView.
        var dataSource = _TrustListView.DataSource as TrustDataSet.TrustsDataTable;
        new TrustWriter(GetConnectionString()).SaveTrusts(dataSource);
    }

And since TrustDataSource does not contain changed values on the ListView, saving it would not work either.

Markup of ListView

<asp:ListView ID="_TrustListView" runat="server">
    <LayoutTemplate>
        <table>
            <thead>
                <th>Client_ID</th>
                <th>Trust_ID</th>
                <th>Trust Name</th>
            </thead>
            <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
        </table>
    </LayoutTemplate>
    <ItemTemplate>
        <tr>
            <td><asp:Label ID="clientIdLabel" runat="server" Text='<%# Eval("Client_ID") %>'></asp:Label></td>
            <td><asp:Label ID="trustIdLabel" runat="server" Text='<%# Eval("Trust_ID") %>'></asp:Label></td>
            <td><asp:Label ID="trustNameLabel" runat="server" Text='<%# Bind("Trust_Name") %>'></asp:Label></td>
        </tr>
    </ItemTemplate>
</asp:ListView>