Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 8th, 2007, 05:34 PM
Registered User
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem controlling rowsate of gridview

I have a gridview with an itemtemplate and an edit template.

I have an "Edit" button on the Itemtemplate which switches the row into edit mode using CommandName="Edit" in the markup.

In the Edittemplate I can change my controls (a textbox and dropdown) and hit "update".
This OnClick fires this:

Protected Sub Update_Ref(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim GridView1 As GridView = Me.grdFullReferrals

        Dim ddlServCompletion As DropDownList = Me.grdFullReferrals.Rows(Me.grdFullReferrals.EditIndex).FindControl("ddlServCompletion")
        Dim tbxCloseDate As TextBox = Me.grdFullReferrals.Rows(Me.grdFullReferrals.EditIndex).FindControl("tbxCloseDate")
        Dim lblReferralID As Label = Me.grdFullReferrals.Rows(Me.grdFullReferrals.EditIndex).FindControl("lblReferralID")
        Dim lblvaltbxCloseDate As Label = Me.grdFullReferrals.Rows(Me.grdFullReferrals.EditIndex).FindControl("lblvaltbxCloseDate")

        If ddlServCompletion.SelectedValue = "7f966087-086e-4370-8894-edec85055bca" Or ddlServCompletion.SelectedValue = "9762222a-6e4d-4ba1-aae6-dcb77267db29" Then ' different from not set and in system
            If Not IsDate(tbxCloseDate.Text) Then
                lblvaltbxCloseDate.Text = "Please enter a date"
                Exit Sub
            End If
        End If

        ds.UpdateParameters("ServiceCompletion").DefaultValue = ddlServCompletion.SelectedValue
        ds.UpdateParameters("CLOSE_DTTM").DefaultValue = tbxCloseDate.Text
        ds.UpdateParameters("ReferralID").DefaultValue = lblReferralID.Text
        ds.UpdateParameters("AmendedBy").DefaultValue = Session("UserID")

        Me.grdFullReferrals.Rows(Me.grdFullReferrals.EditIndex).Rowstate = DataControlRowState.Normal
    End Sub

The problem is that the Update event of the datasource works fine, it changes the row in the database, but the Gridview row remains in the "Edit" state, when I need it to switch back to the normal mode.


Old March 10th, 2007, 06:13 PM
Friend of Wrox
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts

Try manually setting the GridView's EditIndex to -1. That always works for me.

Oh, and if you're populating the GridView manually, you have to explicitly set its DataSource/DataMember and call DataBind() every time you want it to re-render.

Hope that helps.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paging problem in gridview kalyanykk ASP.NET 3.5 Basics 1 December 8th, 2008 03:33 AM
Gridview problem in Binding ndramkumar ASP.NET 2.0 Professional 1 September 2nd, 2007 11:45 PM
problem in gridview jaber.moh ASP.NET 2.0 Basics 1 March 19th, 2007 02:47 AM
Gridview.SelectedRow problem toshesh ASP.NET 2.0 Professional 3 November 30th, 2006 01:01 PM
Problem in GridView mohsin_khan BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 November 15th, 2006 03:07 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.