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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete in Datagrid not refreshing on page

Status
Not open for further replies.

schltzy99

Programmer
Feb 11, 2002
33
US
The problem I am having is that whenever I delete an item from my datagrid the datagrid does not refresh itself. I have the delete linkbutton in the last column which is a template column. The page functions appropriately and deletes the record, but I cannot get it to update the page. I tried placing mydatagrid.databind() within the delete section of the code, but that did not work. Here is what I have:

<script>
function getconfirm()
{
if (confirm(&quot;WARNING! You are about to delete a project. Are you sure you wish to proceed?&quot;))
return true;
else
return false;
}
</script>

<asp:datagrid id=&quot;ProjDataGrid&quot; runat=&quot;server&quot; enableviewstate=&quot;False&quot; AutoGenerateColumns=&quot;False&quot; AllowSorting=&quot;True&quot; BorderColor=&quot;White&quot; GridLines=&quot;None&quot; CellPadding=&quot;2&quot; CellSpacing=&quot;1&quot; Width=&quot;100%&quot;>
<Columns>
<asp:TemplateColumn HeaderText=&quot;Options&quot;>
<ItemTemplate>
<asp:LinkButton id=&quot;cmdDel&quot; onclick=&quot;delete_click&quot; runat=&quot;server&quot; Text=&quot;Delete&quot; CommandName=&quot;Delete&quot; CausesValidation=&quot;false&quot;></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>


'DataGrid Delete LinkButton Functionality
Private Sub ProjDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles ProjDataGrid.ItemDataBound
Dim l As LinkButton
Dim h As HyperLink
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
l = CType(e.Item.Cells(2).FindControl(&quot;cmdDel&quot;), LinkButton)
l.Attributes.Add(&quot;onclick&quot;, &quot;return getconfirm();&quot;)
l.ID = &quot;d&quot; & DataBinder.Eval(e.Item.DataItem, &quot;prID&quot;)
h = CType(e.Item.Cells(2).FindControl(&quot;EditLink&quot;), HyperLink)
h.NavigateUrl = h.NavigateUrl & &quot;&prID=&quot; & DataBinder.Eval(e.Item.DataItem, &quot;prID&quot;) & &quot;&clID=&quot; & DataBinder.Eval(e.Item.DataItem, &quot;clID&quot;)
End If
End Sub

'DataGrid Delete LinkButton Functionality
Sub delete_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim link As LinkButton = CType(sender, LinkButton)
Dim da As New ReviewDAC.DataAccess()
da.DeleteProject(CInt(Right(link.ID, Len(link.ID) - 1)))
End Sub


Thank you very much for your help!!!!! RSchultz
rschultz@fivestardev.com
**Access 2000**
 
Hey Schultz,

Could you tell us what is not being updated on the page?
i.e. you delete a record, rebind the datagrid, but hte record appears again?

If its something like that, then I'd say check that your delete code is actually deleting the record from the datasource the grid is binding to.

jack
 
Jack,

The datagrid is not refreshing the way it should. The delete function does actually delete what I want it to, however when I click on the button the record is deleted but the deleted record still displays on the screen.

Hope that helps to clarify it some.

Rob RSchultz
rschultz@fivestardev.com
**Access 2000**
 
Hmm...

Havd you stepped through the code to make sure that the datagrid's databind is actually going back to the datasource to get the latest data?

J
 
Yeah, which is why I am so confused as to why it wont reload the changes. RSchultz
rschultz@fivestardev.com
**Access 2000**
 
Question:
If you refresh the page (not just f5, but load it up fresh again), then is the record gone? My suspicion is yes.

If so, then try setting up the logic of your page like this:

Abstract all binding logic into one sub, and call it 'bindGrid()'. So that your page_load looks like this:

if not page.ispostback then
bindGrid()
end if

and the delete function has one final line to it:
bindGrid()

----------------

If you answered yes to that first question, then there's only one thing that could be wrong -- the datagrid is either getting loaded from viewstate, or bound before the delete -- which is why the record is still showing.

Keep in mind that the delete function is being called after the page_load event, so if you're binding it in the page_load every time, then that would cause this type of behavior -- since at that point, the record is actually still there. It's then deleted, but the binding has already occured, and the record shows.

hth -
paul
penny1.gif
penny1.gif
 
Paul

Earlier today I tried to make the exact same changes that you mentioned above. A new problem occured. My entire datagrid disappears after I click on the delete link. Viewstate isnt on.

Any further suggestions?

Sorry to be a pain... RSchultz
rschultz@fivestardev.com
**Access 2000**
 
then you didn't bind the grid again. The only thing (that I know of) that causes this type of behavior is forgetting to bind the grid -- and what you are describing is point-on exactly what forgetting to bind it does.

I would be interested in seeing the entire code-behind, or at least the page_load, bindGrid(), and delete_click routines so I can follow the logic to see what's going on.
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top