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

DataGrid Edit/Update/Cancel poroblem 1

Status
Not open for further replies.

jkl

Programmer
May 16, 2001
83
US
I'm using a DataGrid object to return conatct information for members. The returned result is fine.

I'm using an EditCommandColumn to make edits to the returned email and/or phone number. After making the changes to the text box and I hit "Update", the original value of the cells is passed back to the form and not the newly changed value.

i.e.
Original RS: name="John", email="bigJohn@yahoo.com"
Changed to: name="John", email="BigJohnStud@yahoo.com"

Here's my onUpdate function:
========================
Sub Update_List(ByVal source As Object, ByVal e As DataGridCommandEventArgs)

Dim tempStr as String

tempStr = e.Item.Cells(0).Text.ToString() & &quot;, &quot; & e.Item.Cells(0).Text.ToString() & &quot;.<br>&quot;

Response.Write(tempStr)

End Sub
========================

The ouput always comes back as:
&quot;John,bigJohn@yahoo.com&quot; instead of &quot;John,bigJohnStud@yahoo.com&quot;

Any ideas?? Thanks.
 
Do you have a datagird.bind call anywhere in your code that is constantly going back to the original datasource and retrieving that info?

Are you saving the changes to your database or datasource before you're rebinding?

I'd check those things first.

Jack
 
Jack,

Thanks for that lead, but I don't think that's the issue. The function I'm using just does a Response.Write of the data submitted from the form, without going back to the db.
 
Jack,

You were right about the binding. I found an errant call to the databind during the page load. Thanks a lot.

.jimmy.
 
okay, now for me next issue...

currently for this RS, i'm using the table's unique identifier to specify which record to change. as it stands, that id is in a bound column. i don't want to show this id number onscreen.

how can i make the id available to my function without adding it to the datagrid item?

.jimmy.
 
Hey Jimmy,

Each column in the datagrid has a visible property. All you need to do is set visible=false for the ID column.

:)

Jack
 
Go to the Property builder of the datagrid. Choose the columns option from the left side bar. Then under data fields choose which columns you wish to display. The default is all so just pick the ones you want [peace]
 
Thanks guys. Who knew it'd be something as simple as &quot;visible = false&quot;. duh.
 
okay. more stuff.

now that i have that field hidden. how do i reference that ID to pass along to the update procedure?

before, i was using

Dim idField as TextBox = e.Item.Cells(1).Controls(0)

idField.Text.ToString()

Now??
 
You do it the same way, excpet now its just

e.item.cells(1).text

Jack
 
I'm using Dim ID As String = e.Item.Cells(1).Text

however, ID.ToString() is not returning anything.

 
Hmm...make sure the field is set to read only as well. If its hidden, but is still set to editable, then the code may still be putting a text box in there.

If you set it to read only, it should (in theory) work by just accessing the cell's text.

Jack
 
Yep, that was it. Thanks Jack.
 
I am using a datagrid for editing data. I have laid out my grid in a vertical format so that it looks like a form using table tags in an <ItemTemplate> tag.

I have added an EditCommandColumn at the end. However this column will appear on the end. Ideally I want it to appear in the centre of the screen. How can I do this?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top