Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

In my gridview, 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

Posted

Rather than read from the database straight into the gridview, you could always read the data into a dataset or datatable, then assign that to the gridview.

 

However i'd usually change the underlying data in the sites i've created, then just re-read it from the original datasource.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...