LLBLGenDataSource and Inserts

Posts   
 
    
Posts: 497
Joined: 08-Apr-2004
# Posted on: 15-Jun-2007 16:31:48   

Hi all,

I'm trying to use the GridView to do an insert, and not sure what I need to do.. I don't work much with ASP.NET controls, so I'm a little confused at it... Heres what I have done

1) Added an LLBLGenDataSource2 control, no worries there. 2) Bound it to a GridView. Ok, now I can delete and edit. Great. 3) I allow my gridview's command button to show an insert. Hmmm, that doesnt't seem to change anything. So I create a template for the insert that calls a method "AddNewRow"..

Here's where I'm stuck. What do I do now? I just want to add a new blank row for insertion, but the grivdiew doesn't seem to do anything

I have so far added this (kludgey?) code to the AddNewRow method:

        protected void AddNewRow(object sender, EventArgs e)
        {

            // I'm going to add my own row to the database (probably stupid idea!)
            CandidateEntity candidate = new CandidateEntity();
            candidate.Name = "";
            candidate.Username = "user";
            candidate.Password = "password";
            UserManager userManager = new UserManager();
            userManager.AddUser(candidate);

           // Darn, nothing happens when I call this code, so I'll try this...
            GridView1.DataBind(); // This doesn't do anything either
        }

As I have it now, it adds a new row to the DB but doesn't reflect in the gridview until I F5 the page! ITs probably dead easy to do this, please, someone put me out of my misery!

Thanks!

And have a good weekend everyone!

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 15-Jun-2007 18:56:59   

if your using a LLBLDataSource you can do this

protected void AddNewRow(object sender, EventArgs e)
{
     // I'm going to add my own row to the database (probably stupid idea!)
     CandidateEntity candidate = new CandidateEntity();
     candidate.Name = "";
     candidate.Username = "user";
     candidate.Password = "password";
     UserManager userManager = new UserManager();
     userManager.AddUser(candidate);

     [DataSource].Refetch = true;
}

if not you need to manually refetch the data

protected void AddNewRow(object sender, EventArgs e)
{
     // I'm going to add my own row to the database (probably stupid idea!)
     CandidateEntity candidate = new CandidateEntity();
     candidate.Name = "";
     candidate.Username = "user";
     candidate.Password = "password";
     UserManager userManager = new UserManager();
     userManager.AddUser(candidate);

    GridView1.DataSource = userManager.GetUsers();
    GridView1.DataBind();
}
Posts: 497
Joined: 08-Apr-2004
# Posted on: 18-Jun-2007 14:46:08   

I shall try that and see if it works, it looks promising though wink