By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

Refreshing the DataGrid in a webform in the IFrame

P: n/a
Rod
I posted a message to this group yesterday asking how to pass parameters to
a web form that is the source of an IFrame on a parent web form. I've
gotten my answer, and it works. Thanks!

Now I have a different problem. The web form that is in the IFrame has a
DataGrid in it. I have a button column in it which I use to trigger the
deletion of the row in the database, and I want it to also reflect that
deletion in the data grid. The code in the datagrid's DeleteCommand event
is working fine, to delete the row in the database. However, even though I
call the data adapter's Fill method to repopulate the dataset, and then bind
the dataset again to the datagrid, it does not reflect the fact that the
data is now deleted. I have checked the data in the dataset itself, and
have verified that the record I wanted to delete is deleted, so why doesn't
it show that in the datagrid?

Rod
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Rod,

From your description, you used a webform datagrid to display some datas
retrieved from database and the datagrid contains a delete columns to
delete the items. When after the deleting, you update the dataset to
theserver and refill the dataset and bind to the grid again. However, you
found the delelted rows still exist on the datagrid, yes?

As you mentioned that you have checked that the dataset's data has
represnent the correct updated result( no deleted rows) ,yes? Then, I think
the problem is likely due to the rebinding of the datagrid. How do you
rebind the dataset to the datagrid? Maybe it is not correctly rebinded.
Please have a check on it and also it'll be better that you provide some
detailed code snip on this. Thank.s

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #2

P: n/a
Rod
Hi Steve,

This particular application we're using VB.NET for the code behind language.
All of the code snippets I present here are from the web form which is the
target of the IFrame on the parent page.

In the page load event I have the following (this is all within a try-catch
block, which I've omitted for clarity's sake):

'now I have to build a SQL query using spNewVoucherServices20, to retrieve
data
SqlConnection1.ConnectionString = Session("ConnectionString").ToString()
'assign the connection string
SqlConnection1.Open()
ServicesForVoucher.Parameters("@ProviderNumber").V alue =
Convert.ToInt16(nProviderNumber)
ServicesForVoucher.Parameters("@VoucherNumber").Va lue = lVoucherNumber
ServicesForVoucher.Parameters("@ServiceCodeFilter" ).Value =
Convert.ToInt16(nServiceCodeFilter)

'fetch the data
daServicesForVoucher.Fill(DsServicesForVoucher1, "spNewVoucherServices20")

'bind it to the grid
DataGrid1.DataSource = DsServicesForVoucher1.spNewVoucherServices20
DataGrid1.DataBind()

(Please note that I do not consider postback in the page load event.
Basically I am thinking that I will always retrieve the data during each
postback.)

Then the code for the datagrid's delete command I have the following:

Try
DeleteService.Parameters("@ServiceID").Value = lServiceID
daServicesForVoucher.DeleteCommand.ExecuteNonQuery ()
cAmountExpended =
Convert.ToDecimal(DeleteService.Parameters("@Amoun tExpended").Value)
Catch ex As Exception
lblError.Text = ex.Message
lblError.Visible = True
End Try
daServicesForVoucher.Fill(DsServicesForVoucher1, "spNewVoucherServices20")
'refresh the data
DataGrid1.DataSource = DsServicesForVoucher1.spNewVoucherServices20
DataGrid1.DataBind() 'rebind after deleting the service

(Here you see that I am executing the DataBind() method of the datagrid
control, again. I thought this would work, even though it is called from
the page load event, because the datagrid's delete command event is fired
after the page load event.)

Rod

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:g%****************@cpmsftngxa06.phx.gbl...
Hi Rod,

From your description, you used a webform datagrid to display some datas
retrieved from database and the datagrid contains a delete columns to
delete the items. When after the deleting, you update the dataset to
theserver and refill the dataset and bind to the grid again. However, you
found the delelted rows still exist on the datagrid, yes?

As you mentioned that you have checked that the dataset's data has
represnent the correct updated result( no deleted rows) ,yes? Then, I think the problem is likely due to the rebinding of the datagrid. How do you
rebind the dataset to the datagrid? Maybe it is not correctly rebinded.
Please have a check on it and also it'll be better that you provide some
detailed code snip on this. Thank.s

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3

P: n/a
Hi Rod,

Thanks for the followup and the detailed code snippet. I've checked the
code and since you're using a strong type dataset and doing the update and
retrieving via DataAdapte and you mentioned that the records in the dataset
are the correct ones. So I don't think the problem is on the data
manipulcation with database server.

However, as you mentioned that

===================================
(Here you see that I am executing the DataBind() method of the datagrid
control, again. I thought this would work, even though it is called from
the page load event, because the datagrid's delete command event is fired
after the page load event.)
===================================

You put the datagrid's bind code in the Page_Load event handler which is
called before the datagrid's delete command event. I think this maybe the
cause of the problem, since you delete the record and update it to the
database in the DataGrid 's delete command event, you also need to refill
the dataset again in the delete command event. For example:

void dataGrid_Command(Object sender, DataGridCommandEventArgs e)
{

//1.delete the item in dataset
//2.update the dataset to database
//3.retrieve the data from database again(refill the dataset)
//4. set the new filled dataset to datagrid's DataSource and call
DataBind()

}

In addition, since the datagrid bydefault store the items(displaying
records) in its viewstate, we can only do inital databind in Page_Load
rather than everytime, such as

void Page_Load(...)
{
if(!IsPostBack)
{

//Bind data to datagrid
}
}
Please have a check. Hope helps.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #4

P: n/a
Rod
HI Steven,

Thank you for the reply!

I found, thanks to your help, that I needed to purge the dataset of the data
retrieved in the page load event. So, after I deleted the data from the
table, I then called the Clear() method of the dataset against the relevant
table. This cleared the dataset of whatever was in it, and then I retrieved
the data from the database via the data adapter's Fill() method.

Rod

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:ar**************@cpmsftngxa06.phx.gbl...
Hi Rod,

Thanks for the followup and the detailed code snippet. I've checked the
code and since you're using a strong type dataset and doing the update and
retrieving via DataAdapte and you mentioned that the records in the dataset are the correct ones. So I don't think the problem is on the data
manipulcation with database server.

However, as you mentioned that

===================================
(Here you see that I am executing the DataBind() method of the datagrid
control, again. I thought this would work, even though it is called from
the page load event, because the datagrid's delete command event is fired
after the page load event.)
===================================

You put the datagrid's bind code in the Page_Load event handler which is
called before the datagrid's delete command event. I think this maybe the
cause of the problem, since you delete the record and update it to the
database in the DataGrid 's delete command event, you also need to refill
the dataset again in the delete command event. For example:

void dataGrid_Command(Object sender, DataGridCommandEventArgs e)
{

//1.delete the item in dataset
//2.update the dataset to database
//3.retrieve the data from database again(refill the dataset)
//4. set the new filled dataset to datagrid's DataSource and call
DataBind()

}

In addition, since the datagrid bydefault store the items(displaying
records) in its viewstate, we can only do inital databind in Page_Load
rather than everytime, such as

void Page_Load(...)
{
if(!IsPostBack)
{

//Bind data to datagrid
}
}
Please have a check. Hope helps.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.