GridView disapears after entering edit mode.

Discussion in 'ASP .Net Web Controls' started by Michael, Mar 21, 2006.

  1. Michael

    Michael Guest

    Hi Everyone,
    I'm having a problem with the gridview control. When I click on the edit
    link, the grid disapears and don't come back, until I restart the page. I
    have setup the grid as such:
    <asp:GridView ID="grdPOs" runat="server" AllowPaging="True"
    AutoGenerateColumns="False"
    BackColor="White" BorderColor="#CC9966" BorderStyle="None"
    BorderWidth="1px"
    CellPadding="4" Width="692px" DataKeyNames="ItemId">
    <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
    <Columns>
    <asp:BoundField DataField="Page" HeaderText="Page"
    SortExpression="Page">
    <ItemStyle HorizontalAlign="Right" />
    </asp:BoundField>
    <asp:BoundField DataField="CatalogId" HeaderText="Catalog #">
    <ItemStyle HorizontalAlign="Right" Width="80px" />
    </asp:BoundField>
    <asp:BoundField DataField="ItemDescription"
    HeaderText="Description" SortExpression="ItemDescription">
    <ItemStyle Width="250px" />
    </asp:BoundField>
    <asp:BoundField DataField="Qty" HeaderText="Qty"
    SortExpression="Qty">
    <ItemStyle HorizontalAlign="Right" />
    </asp:BoundField>
    <asp:BoundField DataField="UnitPrice"
    DataFormatString="{0:C}" HeaderText="UnitPrice"
    SortExpression="UnitPrice">
    <ItemStyle HorizontalAlign="Right" Width="70px" />
    </asp:BoundField>
    <asp:BoundField DataFormatString="{0:0.00}"
    HeaderText="Total" InsertVisible="False" />
    <asp:CommandField ShowEditButton="True" />
    <asp:ButtonField CommandName="Delete" Text="Delete" />
    <asp:BoundField DataField="POrderId" HeaderText="POrderId"
    InsertVisible="False"
    SortExpression="POrderId" Visible="False" />
    <asp:BoundField DataField="OrderDate" HeaderText="OrderDate"
    SortExpression="OrderDate"
    Visible="False" />
    <asp:BoundField DataField="ItemID" HeaderText="ItemID"
    InsertVisible="False" SortExpression="ItemID"
    Visible="False" />
    </Columns>
    <RowStyle BackColor="White" ForeColor="#330099" />
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
    ForeColor="#663399" />
    <PagerStyle BackColor="#FFFFCC" ForeColor="#330099"
    HorizontalAlign="Center" />
    <HeaderStyle BackColor="#990000" Font-Bold="True"
    ForeColor="#FFFFCC" />
    </asp:GridView>

    And the RowEditing event is as follows.
    Protected Sub grdPOs_RowEditing(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewEditEventArgs) Handles grdPOs.RowEditing
    grdPOs.EditIndex = e.NewEditIndex
    DataBind()
    End Sub

    Has anyone else seen anything like this. Thanks for any advice that you can
    provide.
    Michael
    Michael, Mar 21, 2006
    #1
    1. Advertising

  2. Where is RowEditing being invoked in your GridView declarative statement?
    Plus, where's the data source?
    --
    Christopher A. Reed
    "The oxen are slow, but the earth is patient."

    "Michael" <> wrote in message
    news:...
    > Hi Everyone,
    > I'm having a problem with the gridview control. When I click on the edit
    > link, the grid disapears and don't come back, until I restart the page. I
    > have setup the grid as such:
    > <asp:GridView ID="grdPOs" runat="server" AllowPaging="True"
    > AutoGenerateColumns="False"
    > BackColor="White" BorderColor="#CC9966" BorderStyle="None"
    > BorderWidth="1px"
    > CellPadding="4" Width="692px" DataKeyNames="ItemId">
    > <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
    > <Columns>
    > <asp:BoundField DataField="Page" HeaderText="Page"
    > SortExpression="Page">
    > <ItemStyle HorizontalAlign="Right" />
    > </asp:BoundField>
    > <asp:BoundField DataField="CatalogId" HeaderText="Catalog
    > #">
    > <ItemStyle HorizontalAlign="Right" Width="80px" />
    > </asp:BoundField>
    > <asp:BoundField DataField="ItemDescription"
    > HeaderText="Description" SortExpression="ItemDescription">
    > <ItemStyle Width="250px" />
    > </asp:BoundField>
    > <asp:BoundField DataField="Qty" HeaderText="Qty"
    > SortExpression="Qty">
    > <ItemStyle HorizontalAlign="Right" />
    > </asp:BoundField>
    > <asp:BoundField DataField="UnitPrice"
    > DataFormatString="{0:C}" HeaderText="UnitPrice"
    > SortExpression="UnitPrice">
    > <ItemStyle HorizontalAlign="Right" Width="70px" />
    > </asp:BoundField>
    > <asp:BoundField DataFormatString="{0:0.00}"
    > HeaderText="Total" InsertVisible="False" />
    > <asp:CommandField ShowEditButton="True" />
    > <asp:ButtonField CommandName="Delete" Text="Delete" />
    > <asp:BoundField DataField="POrderId" HeaderText="POrderId"
    > InsertVisible="False"
    > SortExpression="POrderId" Visible="False" />
    > <asp:BoundField DataField="OrderDate"
    > HeaderText="OrderDate"
    > SortExpression="OrderDate"
    > Visible="False" />
    > <asp:BoundField DataField="ItemID" HeaderText="ItemID"
    > InsertVisible="False" SortExpression="ItemID"
    > Visible="False" />
    > </Columns>
    > <RowStyle BackColor="White" ForeColor="#330099" />
    > <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
    > ForeColor="#663399" />
    > <PagerStyle BackColor="#FFFFCC" ForeColor="#330099"
    > HorizontalAlign="Center" />
    > <HeaderStyle BackColor="#990000" Font-Bold="True"
    > ForeColor="#FFFFCC" />
    > </asp:GridView>
    >
    > And the RowEditing event is as follows.
    > Protected Sub grdPOs_RowEditing(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewEditEventArgs) Handles grdPOs.RowEditing
    > grdPOs.EditIndex = e.NewEditIndex
    > DataBind()
    > End Sub
    >
    > Has anyone else seen anything like this. Thanks for any advice that you
    > can
    > provide.
    > Michael
    >
    Christopher Reed, Mar 22, 2006
    #2
    1. Advertising

  3. Michael

    Michael Guest

    Actually, I'm using a dataset to work with the screen. I have setup two
    columns to handle the Delete and Edit functions for the grid:
    <asp:CommandField ShowEditButton="True" />
    <asp:ButtonField CommandName="Delete" Text="Delete" />

    Here is the code for the class(Code-Behind) minus a few saving functions to
    save some space. Here is the code:
    Imports System.Data
    imports System.Data.SqlClient


    Partial Class EnterPOrder
    Inherits System.Web.UI.Page

    Private NetCon as SqlConnection
    Private dsPO as New DataSet
    Private dsPrograms as New DataSet


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles Me.Load
    if not IsPostBack then
    BindData()
    End If
    End Sub


    Private Sub BindData()
    Dim mCommand As SqlCommand
    Dim cnSQL as SqlConnection
    Dim da as new SqlDataAdapter
    try
    cnSQL = OpenConnection()
    mCommand = New SqlCommand
    mCommand.CommandType = CommandType.StoredProcedure
    mCommand.Connection = cnSQL
    mCommand.CommandText = "Admin_GetPurchaseOrders"
    da.SelectCommand = mCommand
    da.Fill(dsPO, "POS")
    grdPOs.DataSource = dsPO.Tables("POS")
    grdPOs.DataBind
    cnSQL.Close
    'SqlDataPOs.DataBind

    'Setup the Programs Listbox.
    cnSQL = OpenConnection()
    mCommand = New SqlCommand
    mCommand.CommandType = CommandType.StoredProcedure
    mCommand.Connection = cnSQL
    mCommand.CommandText = "Admin_GetPrograms"
    da.SelectCommand = mCommand
    da.Fill(dsPrograms, "Programs")
    cmbPrograms.DataSource = dsPrograms.Tables("Programs")
    cmbPrograms.DataTextField = "ProgramName"
    cmbPrograms.DataValueField = "ProgramId"
    cmbPrograms.DataBind
    Catch ex As Exception
    msgbox(ex.Message )
    Finally
    cnSQL.Dispose
    mCommand.Dispose
    da.Dispose
    End Try

    End Sub

    Private Function OpenConnection() as SqlConnection
    try
    NetCon = New SqlConnection
    With NetCon
    .ConnectionString = "packet size=4096;integrated security=SSPI;data
    source=Backupsvr\bkupexec;persist security info=False;initial
    catalog=PurchaseOrders"
    .Open()
    End With
    return NetCon
    Catch ex As Exception
    msgbox(ex.Message )
    return nothing
    End Try
    End Function


    Protected Sub grdPOs_RowEditing(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewEditEventArgs) Handles grdPOs.RowEditing
    grdPOs.EditIndex = e.NewEditIndex
    DataBind()
    End Sub

    Protected Sub grdPOs_RowCancelingEdit(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles
    grdPOs.RowCancelingEdit
    grdPOs.EditIndex = -1
    DataBind()
    End Sub

    Protected Sub grdPOs_RowUpdating(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles grdPOs.RowUpdating
    Dim POid as Integer
    Dim CatalogId as string, Description as string
    Dim Qty as Integer , UnitPrice as Double , Page as Integer
    Dim mCommand As SqlCommand
    Dim cnSQL as SqlConnection
    Dim records(e.NewValues.Count - 1) As DictionaryEntry
    Dim entry As DictionaryEntry
    Dim DataKeyId as DataKey
    try
    'Copy the new values into the fields
    e.NewValues.CopyTo(records, 0)
    For Each entry In records

    e.NewValues(entry.Key) = Server.HtmlEncode(entry.Value.ToString())

    Next
    DataKeyId = grdPOs.DataKeys(e.RowIndex )
    'IntId = DataKeyId.Values("ItemId")

    POid = DataKeyId("ItemId") 'grdPOs.DataKeys(e.RowIndex).Value
    CatalogId = DataKeyId("CatalogId").ToString
    'e.NewValues.Item(1).ToString
    Description = DataKeyId("ItemDescription").ToString
    'CType(e.Item.Cells(2).Controls(0), TextBox).Text
    Qty = DataKeyId("Qty") 'CType(e.Item.Cells(3).Controls(0),
    TextBox).Text
    UnitPrice = DataKeyId("UnitPrice")
    'CType(e.Item.Cells(4).Controls(0), TextBox).Text
    Page = DataKeyId("Page") 'CType(e.Item.Cells(6).Controls(0),
    TextBox).Text
    cnSQL = OpenConnection()
    mCommand = New SqlCommand
    mCommand.CommandType = CommandType.StoredProcedure
    mCommand.Connection = cnSQL
    mCommand.CommandText = "Admin_UpdatePOItem"
    mCommand.Parameters.add("@ItemID", SqlDbType.Int ).Value = POid
    mCommand.Parameters.add("@CatalogeId", SqlDbType.Int ).Value = CatalogId
    mCommand.Parameters.add("@ItemDescription", SqlDbType.VarChar ,250).Value =
    Description
    mCommand.Parameters.add("@Qty", SqlDbType.Int).Value = Qty
    mCommand.Parameters.add("@UnitPrice", SqlDbType.Money ).Value = UnitPrice
    mCommand.Parameters.add("@Page", SqlDbType.int).Direction = Page
    mCommand.ExecuteNonQuery
    grdPOs.EditIndex = -1
    BindData()
    Catch ex As Exception
    msgbox(ex.Message )
    End Try
    End Sub


    Protected Sub grdPOs_RowDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdPOs.RowDataBound
    If e.Row.RowType =DataControlRowType.DataRow then
    e.Row.Cells(5).Text = format(convert.ToInt16(e.Row.Cells(3).Text) *
    convert.ToDouble(e.row.Cells(4).Text), "0.00")
    end if
    End Sub
    End Class

    Does this help any.
    Thanks again for the reply.
    Michael


    "Christopher Reed" wrote:

    > Where is RowEditing being invoked in your GridView declarative statement?
    > Plus, where's the data source?
    > --
    > Christopher A. Reed
    > "The oxen are slow, but the earth is patient."
    >
    Michael, Mar 22, 2006
    #3
  4. Try setting a breakpoint within the grdPOs_RowEditing method and see if it is
    invoked.
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Michael" wrote:

    > Actually, I'm using a dataset to work with the screen. I have setup two
    > columns to handle the Delete and Edit functions for the grid:
    > <asp:CommandField ShowEditButton="True" />
    > <asp:ButtonField CommandName="Delete" Text="Delete" />
    >
    > Here is the code for the class(Code-Behind) minus a few saving functions to
    > save some space. Here is the code:
    > Imports System.Data
    > imports System.Data.SqlClient
    >
    >
    > Partial Class EnterPOrder
    > Inherits System.Web.UI.Page
    >
    > Private NetCon as SqlConnection
    > Private dsPO as New DataSet
    > Private dsPrograms as New DataSet
    >
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    > Handles Me.Load
    > if not IsPostBack then
    > BindData()
    > End If
    > End Sub
    >
    >
    > Private Sub BindData()
    > Dim mCommand As SqlCommand
    > Dim cnSQL as SqlConnection
    > Dim da as new SqlDataAdapter
    > try
    > cnSQL = OpenConnection()
    > mCommand = New SqlCommand
    > mCommand.CommandType = CommandType.StoredProcedure
    > mCommand.Connection = cnSQL
    > mCommand.CommandText = "Admin_GetPurchaseOrders"
    > da.SelectCommand = mCommand
    > da.Fill(dsPO, "POS")
    > grdPOs.DataSource = dsPO.Tables("POS")
    > grdPOs.DataBind
    > cnSQL.Close
    > 'SqlDataPOs.DataBind
    >
    > 'Setup the Programs Listbox.
    > cnSQL = OpenConnection()
    > mCommand = New SqlCommand
    > mCommand.CommandType = CommandType.StoredProcedure
    > mCommand.Connection = cnSQL
    > mCommand.CommandText = "Admin_GetPrograms"
    > da.SelectCommand = mCommand
    > da.Fill(dsPrograms, "Programs")
    > cmbPrograms.DataSource = dsPrograms.Tables("Programs")
    > cmbPrograms.DataTextField = "ProgramName"
    > cmbPrograms.DataValueField = "ProgramId"
    > cmbPrograms.DataBind
    > Catch ex As Exception
    > msgbox(ex.Message )
    > Finally
    > cnSQL.Dispose
    > mCommand.Dispose
    > da.Dispose
    > End Try
    >
    > End Sub
    >
    > Private Function OpenConnection() as SqlConnection
    > try
    > NetCon = New SqlConnection
    > With NetCon
    > .ConnectionString = "packet size=4096;integrated security=SSPI;data
    > source=Backupsvr\bkupexec;persist security info=False;initial
    > catalog=PurchaseOrders"
    > .Open()
    > End With
    > return NetCon
    > Catch ex As Exception
    > msgbox(ex.Message )
    > return nothing
    > End Try
    > End Function
    >
    >
    > Protected Sub grdPOs_RowEditing(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewEditEventArgs) Handles grdPOs.RowEditing
    > grdPOs.EditIndex = e.NewEditIndex
    > DataBind()
    > End Sub
    >
    > Protected Sub grdPOs_RowCancelingEdit(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles
    > grdPOs.RowCancelingEdit
    > grdPOs.EditIndex = -1
    > DataBind()
    > End Sub
    >
    > Protected Sub grdPOs_RowUpdating(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles grdPOs.RowUpdating
    > Dim POid as Integer
    > Dim CatalogId as string, Description as string
    > Dim Qty as Integer , UnitPrice as Double , Page as Integer
    > Dim mCommand As SqlCommand
    > Dim cnSQL as SqlConnection
    > Dim records(e.NewValues.Count - 1) As DictionaryEntry
    > Dim entry As DictionaryEntry
    > Dim DataKeyId as DataKey
    > try
    > 'Copy the new values into the fields
    > e.NewValues.CopyTo(records, 0)
    > For Each entry In records
    >
    > e.NewValues(entry.Key) = Server.HtmlEncode(entry.Value.ToString())
    >
    > Next
    > DataKeyId = grdPOs.DataKeys(e.RowIndex )
    > 'IntId = DataKeyId.Values("ItemId")
    >
    > POid = DataKeyId("ItemId") 'grdPOs.DataKeys(e.RowIndex).Value
    > CatalogId = DataKeyId("CatalogId").ToString
    > 'e.NewValues.Item(1).ToString
    > Description = DataKeyId("ItemDescription").ToString
    > 'CType(e.Item.Cells(2).Controls(0), TextBox).Text
    > Qty = DataKeyId("Qty") 'CType(e.Item.Cells(3).Controls(0),
    > TextBox).Text
    > UnitPrice = DataKeyId("UnitPrice")
    > 'CType(e.Item.Cells(4).Controls(0), TextBox).Text
    > Page = DataKeyId("Page") 'CType(e.Item.Cells(6).Controls(0),
    > TextBox).Text
    > cnSQL = OpenConnection()
    > mCommand = New SqlCommand
    > mCommand.CommandType = CommandType.StoredProcedure
    > mCommand.Connection = cnSQL
    > mCommand.CommandText = "Admin_UpdatePOItem"
    > mCommand.Parameters.add("@ItemID", SqlDbType.Int ).Value = POid
    > mCommand.Parameters.add("@CatalogeId", SqlDbType.Int ).Value = CatalogId
    > mCommand.Parameters.add("@ItemDescription", SqlDbType.VarChar ,250).Value =
    > Description
    > mCommand.Parameters.add("@Qty", SqlDbType.Int).Value = Qty
    > mCommand.Parameters.add("@UnitPrice", SqlDbType.Money ).Value = UnitPrice
    > mCommand.Parameters.add("@Page", SqlDbType.int).Direction = Page
    > mCommand.ExecuteNonQuery
    > grdPOs.EditIndex = -1
    > BindData()
    > Catch ex As Exception
    > msgbox(ex.Message )
    > End Try
    > End Sub
    >
    >
    > Protected Sub grdPOs_RowDataBound(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdPOs.RowDataBound
    > If e.Row.RowType =DataControlRowType.DataRow then
    > e.Row.Cells(5).Text = format(convert.ToInt16(e.Row.Cells(3).Text) *
    > convert.ToDouble(e.row.Cells(4).Text), "0.00")
    > end if
    > End Sub
    > End Class
    >
    > Does this help any.
    > Thanks again for the reply.
    > Michael
    >
    >
    > "Christopher Reed" wrote:
    >
    > > Where is RowEditing being invoked in your GridView declarative statement?
    > > Plus, where's the data source?
    > > --
    > > Christopher A. Reed
    > > "The oxen are slow, but the earth is patient."
    > >

    >
    Phillip Williams, Mar 23, 2006
    #4
  5. Michael

    Ukraine Guest

    Ukraine, Apr 2, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael
    Replies:
    2
    Views:
    6,239
    Michael
    Nov 9, 2005
  2. =?Utf-8?B?TWljaGFlbA==?=

    GridView disapears after selecting Edit

    =?Utf-8?B?TWljaGFlbA==?=, Apr 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,941
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Apr 13, 2006
  3. boardrider
    Replies:
    0
    Views:
    729
    boardrider
    Aug 24, 2006
  4. =?Utf-8?B?QWRhciBXZXNsZXk=?=

    GridView not entering Line Editing mode when inside FormView

    =?Utf-8?B?QWRhciBXZXNsZXk=?=, May 10, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    517
    Steven Cheng[MSFT]
    May 28, 2007
  5. Jaime Stuardo

    GridView control enters edit mode when I click Edit link twice

    Jaime Stuardo, Apr 7, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    390
    Jaime Stuardo
    Apr 7, 2006
Loading...

Share This Page