Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > GridView disapears after entering edit mode.

Reply
Thread Tools

GridView disapears after entering edit mode.

 
 
Michael
Guest
Posts: n/a
 
      03-21-2006
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

 
Reply With Quote
 
 
 
 
Christopher Reed
Guest
Posts: n/a
 
      03-22-2006
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:964241C9-B5F0-4030-AA22-...
> 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
>



 
Reply With Quote
 
 
 
 
Michael
Guest
Posts: n/a
 
      03-22-2006
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.GridViewCancelEditEventA rgs) 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."
>


 
Reply With Quote
 
Phillip Williams
Guest
Posts: n/a
 
      03-23-2006
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.GridViewCancelEditEventA rgs) 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."
> >

>

 
Reply With Quote
 
Ukraine
Guest
Posts: n/a
 
      04-02-2006
Set EnableViewState to true
---
Posted via www.DotNetSlackers.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView disapears after selecting Edit =?Utf-8?B?TWljaGFlbA==?= ASP .Net 2 04-13-2006 03:15 PM
How to make GridView entering edit mode by code? Michael ASP .Net 2 11-09-2005 04:28 PM
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM
Outlook Express POP3 setting disapears Andy Wilson Computer Support 5 09-07-2003 03:32 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57