burak Posted March 30, 2006 Posted March 30, 2006 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 Quote
Jay1b Posted April 6, 2006 Posted April 6, 2006 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.