datagrid hell

N

Nishen Naidoo

Hi,
I have this datagrid on a page with two columns viz ID and Category. I want
users to be able to edit the category data.
This is what I got. When I uncomment the postback below, the grid
dissappears when I click the edit link. As it stands, the Update event is
not triggered. When I click the edit link, a text box appears in the
category column for that row. I then change it and click update. I then
want to see the new data in my test label (txt.text = newData).

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Category_SqlDataAdapter.Fill(Category_Dataset)

'If Not IsPostBack Then

' Category_Datagrid.DataBind()

'End If

Category_Datagrid.DataBind()

End Sub

Private Sub Category_Datagrid_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
Category_Datagrid.EditCommand

Category_Datagrid.EditItemIndex = e.Item.ItemIndex

Category_Datagrid.DataBind()

txt.Text = e.Item.ItemIndex

End Sub

Private Sub Category_Datagrid_UpdateCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
Category_Datagrid.UpdateCommand

Dim newData As String

Dim aTextBox As TextBox

aTextBox = CType(e.Item.Cells(1).Controls(0), TextBox)

newData = aTextBox.Text

txt.Text = newData

End Sub

Am i missing something?

thanx
Nish
 
J

Justin Dutoit

I'm not following your question too well, but when you Update a grid, you
have to databind it again. You know that if you databind in Page Load the
event is reset and won't fire, don't you? So you probably want to use that
If Not IsPostBack, and then call databind at the end of Update.

I think your Update might have worked, you just didn't see it since you
didn't databind. If you Update and see nothing, refresh your browser and see
what happens, that will prove it.

hth
Justin Dutoi
 
J

Justin Dutoit

I didn't see a
Category_Datagrid.DataSource = something
line in ..EditCommand

Is the code you posted, all your code? And do you havein EditCommand?

It would help if you could upload the page to somewhere, with the
server-side code pasted as text into the body, and post a link.


Justin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,200
Latest member
LaraHunley

Latest Threads

Top