Editable Gridview requires two clicks?

Have gridview with coded datasource (ie not using wizard) with "edit" column which only goes into edit mode if you click it twice. See:

Protected Sub dgPInv_RowEditing... below in vb section.
Invent4.aspx:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" BackColor="LightGray" Height="23px" Style="z-index: 103;
        left: 5px; top: 18px" Width="117px">Client Code/Name:</asp:Label>
    <asp:TextBox id="iClCode" style="Z-INDEX: 102; LEFT: 155px; TOP: 18px" runat="server"
		Height="18px" Width="162px"></asp:TextBox>&nbsp; <asp:Label ID="Label2" runat="server" BackColor="LightGray" Height="23px"
        Text="Units:" Width="53px"></asp:Label>
    &nbsp;<asp:TextBox ID="strUnits" runat="server" Height="18px" Width="42px"></asp:TextBox>    
    <asp:Button ID="Update" runat="server" Text="Save Selected" Width="103px" />&nbsp;
    <asp:Button ID="cmdOutput" runat="server" Text="Send to Excel/Word" Width="130px" />
    <asp:Button ID="cmdAll" runat="server" Text="Select All" Width="115px" />
    <asp:Button ID="cmdClear" runat="server" Text="Clear Selection" Width="115px" />
    <asp:GridView ID="dgPInv" runat="server" AllowPaging="True" AutoGenerateColumns="False" Width="988px" AllowSorting="True" DataKeyNames="InventNo">
            <Columns>
            <asp:CommandField ButtonType="Button" ShowSelectButton="True" ><HeaderStyle ForeColor="White" />
            </asp:CommandField>                
                <asp:CommandField ShowEditButton="True" >
                    <ItemStyle Width="65px" />
                </asp:CommandField>
                <asp:CheckBoxField DataField="iSelect" />
            <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" ReadOnly="True" />
            <asp:BoundField DataField="clInventNo" HeaderText="Client Inv No" SortExpression="clInventNo" ReadOnly="True" />
            <asp:BoundField DataField="clInventNo2" HeaderText="Cat No" SortExpression="clInventNo2" ReadOnly="True" />
            <asp:BoundField DataField="ArtistMaker" HeaderText="Artist" SortExpression="ArtistMaker" ReadOnly="True" />
            <asp:BoundField DataField="ShortDesc" HeaderText="Title" SortExpression="ShortDesc" ReadOnly="True" />
            <asp:BoundField DataField="Medium" HeaderText="Medium" SortExpression="Medium" ReadOnly="True" />
            <asp:BoundField DataField="iDate" HeaderText="Date" SortExpression="iDate" ReadOnly="True" />
            <asp:BoundField DataField="Height" HeaderText="Length" SortExpression="Height" ReadOnly="True" />
            <asp:BoundField DataField="Width" HeaderText="Width" SortExpression="Width" ReadOnly="True" />
            <asp:BoundField DataField="Depth" HeaderText="Height" SortExpression="Depth" ReadOnly="True" />
            <asp:BoundField DataField="AcquPriceEquiv" HeaderText="Value" SortExpression="AcquPriceEquiv" DataFormatString="{0:C}" HtmlEncode="False" ReadOnly="True" />
                <asp:ImageField DataImageUrlField="PicFile1" DataImageUrlFormatString="Images/A009/Thumbs/{0}" ReadOnly="True">
                </asp:ImageField>
            <asp:BoundField DataField="Pending" HeaderText="Pending" SortExpression="Pending"
                Visible="False" ReadOnly="True" />
        </Columns>
       <HeaderStyle BackColor="Navy" ForeColor="White" Font-Size="Small" />
        <PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" />
    </asp:GridView>
</asp:Content>
 
Invent4.aspx.vb:
Imports System.Data.SqlClient
Partial Class Invent4
    Inherits System.Web.UI.Page
    Private invconn As SqlConnection
    Private invComm As SqlCommand
    Private da As SqlDataAdapter
    Private ds As Data.DataSet
    Private dt As Data.DataTable
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("Private") = False Then Response.Redirect("Default.aspx")
        If IsPostBack = False Then
            Me.iClCode.Text = Request.QueryString("txtClCode").ToString
            Using invconn = New SqlConnection(ConfigurationManager.ConnectionStrings("Connectstring").ConnectionString)
                invconn.Open()
                Using invComm = New SqlCommand("cClInv", invconn)
                    invComm.CommandType = Data.CommandType.StoredProcedure
                    invComm.Parameters.AddWithValue("@ClCode", Request.QueryString("txtClCode"))
                    Dim da As New SqlDataAdapter(invComm)
                    Dim ds As New Data.DataSet
                    Dim dt As New Data.DataTable
                    da.Fill(ds, "Inventory")
                    dt = ds.Tables("Inventory")
                    dgPInv.DataSource = ds.Tables("Inventory")
                    dgPInv.DataBind()
                    Me.strUnits.Text = dt.Rows.Count.ToString
                    Session("myds") = ds
                End Using
            End Using
        End If
    End Sub
 
    Protected Sub dgPInv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles dgPInv.PageIndexChanging
        dgPInv.PageIndex = e.NewPageIndex
        ds = CType(Session("myds"), Data.DataSet)
        dgPInv.DataSource = ds
        dgPInv.DataBind()
    End Sub
 
    Protected Sub dgPInv_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgPInv.SelectedIndexChanged
        Dim index As Integer = dgPInv.SelectedIndex
        Response.Redirect("InvPart.aspx?txtInvNo=" + Me.dgPInv.DataKeys(index).Value.ToString)
    End Sub
    Protected Sub dgPInv_RowDataBound1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles dgPInv.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim img As Image = CType(e.Row.Cells(14).Controls(0), Image)
            Dim Pending As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Pending"))
            img.ImageUrl = img.ImageUrl.Replace("A009", Session("ClCode"))
            If Pending = 1 Then
                e.Row.BackColor = Drawing.Color.LightCoral
            ElseIf Pending = 2 Then
                e.Row.BackColor = Drawing.Color.CadetBlue
            ElseIf Pending = 3 Then
                e.Row.BackColor = Drawing.Color.Crimson
            End If
        End If
    End Sub
 
    Protected Sub dgPInv_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles dgPInv.RowEditing
        dgPInv.EditIndex = e.NewEditIndex
    End Sub
 
    Protected Sub dgPInv_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles dgPInv.RowCancelingEdit
        dgPInv.EditIndex = -1
    End Sub
 
    Protected Sub dgPInv_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles dgPInv.RowUpdating
        Dim c As CheckBox
        c = CType(dgPInv.Rows(e.RowIndex).Cells(2).Controls(0), CheckBox)
        ds = CType(Session("myds"), Data.DataSet)
        ds.Tables("Inventory").Rows(e.RowIndex).Item("iSelect") = c.Checked
        Session("myds") = ds
        dgPInv.EditIndex = -1
        dgPInv.DataSource = ds.Tables("Inventory")
        dgPInv.DataBind()
    End Sub
 
    Protected Sub Update_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Update.Click
        Using invconn = New SqlConnection(ConfigurationManager.ConnectionStrings("Connectstring").ConnectionString)
            invconn.Open()
            Using invComm = New SqlCommand("cClInv", invconn)
                invComm.CommandType = Data.CommandType.StoredProcedure
                invComm.Parameters.AddWithValue("@ClCode", Request.QueryString("txtClCode"))
                da = New SqlDataAdapter(invComm)
                Dim cmdB As SqlCommandBuilder = New SqlCommandBuilder(da)
                da.UpdateCommand = cmdB.GetUpdateCommand()
                Dim dsUpdated As Data.DataSet
                dsUpdated = CType(Session("myds"), Data.DataSet)
                da.Update(dsUpdated, "Inventory")
            End Using
        End Using
    End Sub
End Class

Open in new window

eharfordAsked:
Who is Participating?
 
prairiedogConnect With a Mentor Commented:
Rebind your GridView after you set the editindex at line 102:
ds = CType(Session("myds"), Data.DataSet)
dgPInv.DataSource = ds
dgPInv.DataBind()
 
0
 
eharfordAuthor Commented:
Many thanks. Immediate response to my question (within minutes!). I am v grateful
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.