Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disappearing DataGrid use ASP control, but prob is in C# codebehind

Status
Not open for further replies.

SimonDoc

Programmer
Jun 10, 2002
1
GB
Hello,

I have a problem with disappearing datagrids.

I have a DG (dgFinance) on the aspx page. I execute my SQL in the Page_Load section and assign the dataset to the datagrid on the aspx page.

DataSet ds = myBusinessLogicObject.DoSQLReturnDataset();
dgFinance.DataSource = ds;
dgFinance.DataBind();

I have tried two scenarios with and without the IsPostBack - as I only really want to go to the database once (on the 1st page load).

Scenario 1 - not using IsPostBack (so the DG is rebound to a new SQL result after every mnouse click!!)

I am using an Edit/Update/Cancel column. I can select Edit and the column changes to update / cancel. When I select update - nothing happens. I can't see the old values. When I stop the code in the dgFinance_UpdateCommand the DataGrid and DataSource contain the old values, so I can't even update the real database. How do I get the new values? -- I think it may be because I am going to the database and 'resetting' the datagrid every time a Page_Load kicks in.

However ...

Scenario 2 - I am using IsPostBack to ensure my SQL is executed once and only once.

If I use IsPostBack ...

if (!IsPostBack)
{
DataSet ds = myBusinessLogicObject.DoSQLReturnDataset();
dgFinance.DataSource = ds;
dgFinance.DataBind();
}

... to ensure that I only physically go the database once. When I select the edit action and breakpoint on the first line in Page_Load I can see fully constructed dgFinance object. But it isn't displayed. From a users perspective you click edit on a row and the whole dataset disappears - Why? The page seems to have a fully constructed dgFinance object - so why doesn't it show.

OK so thats the background, heres my question :

I have looked at many, many examples and most only show code embedded into the aspx file in script tags. The only examples I have found that bind via CodeBehind files do not use the IsPostBack, but I don't want to go to the database after every mouse click. How do I get the new value edited in the text box????

Thanks in advance,

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top