المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Datagrid object binding and saving back



C# Programming
07-07-2012, 06:41 PM
Hi All,

I have created an object book which is as follows

public class book
{
public string bookname;
public string bookauthor;
public string bookprice;
}

public class books:List
{
}

now on the load of the page i get some book details stored in the database and add them to the "books" object and also I add a empty book object to the books so which can be used by the users to add one new book.

I then bind this to a datagrid on the aspx page with template columns.

Books books = new Books();
books=Books.getBooks(); //also adds on blank book object
dgbooks.datasource = books;
dgbooks.databind();

on click of the save button i require the datasource to be type cast as books object. I am trying to do this on the click event of the save button

books = (Books)dgbooks.datasource;

but this is not working because the datasource is entry. Because during the postback it is wiped off. Can someone please help me to come around with this one?

The above code is just a sample code.. hence please ignore the mistakes.
Jack Sparrow
--------------------------------------
Defeat is not the worst of failures. Not to have tried is the true failure.