Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
'Refreshing' SQLDataSource with new data
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01346714
Message ID:
01346766
Views:
15
>Sorry, I can't directly answer your question. If you're already going to be taking some control over creating a dataset yourself (as opposed to using SQLDataSource (eg. modifying it's SelectCommand or something, then forcing it to requery), why not just go all the way and get rid of SQLDataSource altogether? Then you've got full control over how/when the GridView is bound. From the questions you've been asking about this it looks like you're sort of bumping into the limitations of the control anyway. FWIW - this is how I handle all of my web forms. I call out to a business object which is responsible for retrieving me a dataset, then I explicitly set it to bind to my grid. I have full control over when that happens, what data is included, how it gets filtered, etc.
>
>However, you can have multiple SQLDataSource objects and swap the DataSourceID of the GridView between them. That should force it to refresh the grid with the new data.

We actually switched to using dataset for the GridView always. All seems to work OK except that it's not yet clear how to handle Delete event.

When we were using SQLDataSource it has DeleteCommand and we only had code in RowDeleted event. Everything else was handled automatically.

Now we put code in RowDeleting (my colleague's attempts) and the RowDeleted event is never fired as well as this code doesn't seem to do the job. Can you help a bit here?

Thanks in advance.
 protected void ProfilesGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = (int)this.ProfilesGrid.DataKeys[e.RowIndex].Values["PersonID"];

        //   int perid=  (int) Convert.ToInt16(this.ProfilesGrid.SelectedDataKey.Value);
        //{
        string SQL = "UPDATE People SET Deleted = 1 WHERE PersonID = " + id;
        //        e.CommandArgument;
        Util.DoCmd(SQL);

        int pi = ProfilesGrid.PageIndex * 19;
        if (Session["dts"] != null)
        {
            DataSet dts = (DataSet)Session["dts"];
            
            dts.Tables[0].Rows[e.RowIndex+pi].Delete();
            ProfilesGrid.DataSource = dts;
            ProfilesGrid.DataBind();
            Session.Clear();
            Session.Add("dts", dts);
        }

    }
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform