Read edited values on postback in datagrid template column

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I have a datagrid with a template column which as a textbox in it. The user
can change the value in this text box for many different rows. When the
user clicks on the update button, in the code behind I want to loop through
the rows of the datagrid and capture an values that have been changed. I
cant see any way to access the return values (or textboxes for that matter).
Is there a way to do this? and can you someone refer me to some sample code?
I'm using vb.net 1.1.

Thanks.
 
Hi Moondaddy,

From your descriptoin, you've a webform datagrid which contains a template
columns with a textbox in it.
You want to loopthrought the datagrid's items and retrieve the vlaue in the
textbox of every item in
a certain button's click event(post back),yes?

As for this question, I think you can use the DataGrid's "Items" property
to loopthrough all its items and then use the "FindControl" of the certain
Cell and retrieve the control you want:
For example, we have a datagrid named "dgMain" and has a TextBox named
"txtName" in the third Cell, then in a certain post back event, we can use
the following code to retieve the textbox in each datagriditem:

Private Sub dgMain_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgMain.ItemDataBound
Dim item As DataGridItem
For Each item In dgMain.Items

Dim txt As TextBox = item.Cells(2).FindControl("txtName")

Next
End Sub

In addition, here is a KB article which provide a complete code sample on
loop through a DataGrid's Items and retieve a checkbox control in each
item. Please refer to it if you have anything unclear:

#HOW TO: Loop Through and Examine CheckBox Control Values in a DataGrid
Column by Using ASP.NET and Visual Basic .NET
http://support.microsoft.com/?id=321881


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
 
Back
Top