How do I change a datarow in a Gridview?

B

Burak Gunay

Hi,

in my gridview row, I have two BoundField columns and a templatefield
column as follows

<asp:GridView>
<Columns>
<asp:BoundField DataField="ams" HeaderText="Ams" ReadOnly="True"/>
<asp:BoundField DataField="ams_desc" HeaderText="Desc"
ReadOnly="True"/>
<asp:TemplateField HeaderText="AmsTest" ItemStyle-Wrap="true"
HeaderStyle-
Width="120">
<ItemTemplate>
<asp:TextBox ID="txtStudents" Text='<%# Eval("val") %>'
AutoPostBack="true"
OnTextChanged="HandleTextChange"
runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:SQLDataSource ID="sqlProducts" Runat="Server"
SelectCommand = "SELECT ams, ams_desc From audit_ams"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>">
</asp:SQLDataSource>

when a user changes the value in the textbox and presses enter, I call
this event and change the values in the first two columns

Public Sub HandleTextChange(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim x As TextBox
x = CType(sender, TextBox)

Dim y As System.Web.UI.WebControls.DataControlFieldCell
y = CType(x.Parent, System.Web.UI.WebControls.DataControlFieldCell)

Dim z As System.Web.UI.WebControls.GridViewRow
z = CType(y.Parent, System.Web.UI.WebControls.GridViewRow

z.cells(0).text = "some value" -> changes the first boundfield column
z.cells(1).text = "other value" -> changes the second boundfield column


End Sub

but when I move to a different page, I lose the values, since the
change was not made to the underlying datatable.

I tried to get the underlying datarow as follows

Dim f As DataRow
f = CType(z.DataItem, Data.DataRow)

but nothing happened.

How can I change the underlying datarow for this GridViewRow?

Thanks,

Burak
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top