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

Rebinding Datagrid Problems

Status
Not open for further replies.

Lbob

Programmer
May 23, 2003
157
0
0
GB
Hi

Me again....I've got a datagrid that is essentially a calendar. Within each cell I have a button that allows an event to be booked. When the button is clicked a confirmation screen appears which is a form within a div tag. When the user is happy with the information being booked, it is written to the database and the calendar grid is refreshed. However.....after the data is written to the database the grid I'm calling the databind function which for some reason is not clearing down the existing grid and just tacking the new grid onto the existing one.
I've tried setting the datasource to nothing before rebinding but no joy.
Please can anyone help as this is driving me mad!
Cheers
Lbob
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Page.IsPostBack = False Then
RdbYes.Attributes.Add("OnClick", "RdbYes_Click();")
RdbNo.Attributes.Add("OnClick", "RdbNo_Click();")
End If

bindData(sDate)
End Sub

Private Sub bindData(sDate as string)

Dim ds As DataSet,dt As New DataTable("Tbl"),dv As DataView
Dim i As Int32, c As Int32, r As Int32, k As Int32


ds = ListCalendar(sDate)
.....omitted the setting of dt for space reasons

GrdData.DataSource = dt
GrdData.DataBind()

ds.Dispose()
dt.Dispose()

End Sub

Private Sub btnConfirmOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirmOK.Click

....write back to db

.....then rebind datagrid

divConfirmation.Style.Item("display") = "none"
DivShim.Style.Item("display") = "none"

GrdData.DataSource = nothing
GrdData.databind

bindData(sDate)

End Sub



 
One issue you have is that you are binding the data on every load of the page (which includes when you click a button and/or make any other type of postback)!
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        If Page.IsPostBack = False Then
            RdbYes.Attributes.Add("OnClick", "RdbYes_Click();")
            RdbNo.Attributes.Add("OnClick", "RdbNo_Click();")
            [!]bindData(sDate)[/!]
        End If

        [!][s]bindData(sDate)[/s][/!]
End Sub


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

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Hi

Thanks, I've changed it as you said, but now when I click on my book button which I've created dynamically in the grid, the grid disappears and my confirm screen isn't displayed.

Lbob

in my itemdatabound this is what I've got...

btn = New Button
btn.Text = "Book"

btn.ID = e.Item.Cells(i).Text
btn.CssClass = "btn"

AddHandler btn.Click, AddressOf btn_Click
e.Item.Cells(i).Controls.Add(btn)

e.Item.Cells(i).VerticalAlign = VerticalAlign.Top

Then my btnclick function

Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)


divConfirmation.Style.Item(display") = "block"
DivShim.Style.Item("display") = "block"

end sub
 
Because i'm using it with dates across the top and people along the side, so you can see who's in or out.
Lbob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top