473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Preserve Data to Edit on DataGrid When Filtering

Hello All,

I have a webpage that has two dropdown listboxes. Based on what is selected
in these dropdown listboxes, it filters a DataGrid . That works fine.

In the DataGrid , when I go to edit a row, I change the textbox (or other
control), click Update, but it doesn't save my data. I then did this...

In Page_Load, I added code to filter the DataGrid only when it was Not
Page.IsPostBack. Then the editing/updating of the DataGrid data works fine.
But, of course, I lose the ability to filter the DataGrid.

Obviously the problem is with the Postback. But how am I able to have both
the postback and the editing available simultaneously?

I had heard that I should stay away from Session variables, but that seems
that it might work here. Is there another way to do this without Session
variables?

Thank you for the help.
Jan 5 '06 #1
2 2051
You could always do ViewState["FilterVar1"] = "accounting" or something
similar if you didn't want to do session. Some code might help as your
problem could be in several areas (i'm guessing it's a re-binding problem).

-Darren Kopp
http://blog.secudocs.com

"Gummy" <gu***@nowhere.com> wrote in message
news:11*************@corp.supernews.com...
Hello All,

I have a webpage that has two dropdown listboxes. Based on what is
selected
in these dropdown listboxes, it filters a DataGrid . That works fine.

In the DataGrid , when I go to edit a row, I change the textbox (or other
control), click Update, but it doesn't save my data. I then did this...

In Page_Load, I added code to filter the DataGrid only when it was Not
Page.IsPostBack. Then the editing/updating of the DataGrid data works
fine.
But, of course, I lose the ability to filter the DataGrid.

Obviously the problem is with the Postback. But how am I able to have both
the postback and the editing available simultaneously?

I had heard that I should stay away from Session variables, but that seems
that it might work here. Is there another way to do this without Session
variables?

Thank you for the help.

Jan 5 '06 #2
Darren,

Thank you for the information. I have to go look at exactly what ViewState
does (I'm a newbie).

If you want, here's the code. I hope it helps and isn't too messy. As an
aside, I am getting very random "Object reference not set to an instance of
an object" error that I am having problem tracking down. If you see
something, please let me know.

Thank you so much for the help,

----------------------------------------
Public Class CreateParent
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents chkboxMaxDate As System.Web.UI.WebControls.CheckBox
Protected WithEvents dgParents As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Protected WithEvents ucStructureRollupDropDown As New
SelectTypeDropDownBoxes
Protected WithEvents HeaderTab1 As New HeaderTab
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then

FillDataGrid_Parent_Filter(ucStructureRollupDropDo wn.StructureValue,
ucStructureRollupDropDown.RollupValue)
End If

End Sub
Private Sub FillDataGrid_Parent()
Dim strConn As String
Dim strSQL As String
Dim dt As New RobData.DataTransfer
Dim dv As DataView
Try
strConn = dt.OracleConnect("rptpr01", "rptuser", "r00ster")

' strSQL = String.Format("SELECT * from RLUP_PARENT")
strSQL = String.Format("select a.*, rt.rollupdesc,
st.structuredesc from rlup_parent a" & _
" join rlup_rolluptype rt on a.rollupid = rt.rollupid " & _
" join rlup_structuretype st on a.structureid = st.structureid " &
_
" order by a.parentdesc, a.effdt desc")

dv = dt.GetDataSet(strSQL, strConn).Tables(0).DefaultView

dgParents.DataSource = dv 'dt.GetDataSet(strSQL, strConn)

' TempDataView = dt.GetDataSet(strSQL,
strConn).Tables(0).DefaultView

dgParents.DataBind()

Catch ex As Exception
Throw ex

End Try

End Sub

Private Sub FillDataGrid_Parent_Filter(ByVal _structureID As String,
ByVal _rollupID As String)

Dim strConn As String
Dim strSQL As String
Dim dt As RobData.DataTransfer

Try
strConn = dt.OracleConnect("rptpr01", "rptuser", "r00ster")
strSQL = String.Format("select a.*, rt.rollupdesc,
st.structuredesc from rlup_parent a" & _
" join rlup_rolluptype rt on a.rollupid = rt.rollupid " & _
" join rlup_structuretype st on a.structureid = st.structureid
" & _
" where a.structureid Like '{0}%' and a.rollupid like '{1}%' " &
_
" order by a.parentdesc, a.effdt desc", _structureID,
_rollupID)

dgParents.DataSource = dt.GetDataSet(strSQL, strConn)
dgParents.DataBind()

Catch ex As Exception
Throw ex
End Try
End Sub


Private Sub dgParents_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgParents.EditCommand
Dim strSQL As String
Dim strConnect As String
Dim strProjectID As String
Dim dtEffectDate As Date

Dim strConn As String
Dim dt As RobData.DataTransfer
Try

'Item that it is going to be edited
dgParents.EditItemIndex = e.Item.ItemIndex
strConn = dt.OracleConnect("rptpr01", "rptuser", "r00ster")
strSQL = String.Format("select a.*, rt.rollupdesc,
st.structuredesc from rlup_parent a" & _
" join rlup_rolluptype rt on a.rollupid = rt.rollupid " & _
" join rlup_structuretype st on a.structureid = st.structureid
" & _
" order by a.parentdesc, a.effdt desc")
dgParents.DataSource = dt.GetDataSet(strSQL, strConn)
dgParents.DataBind()

Catch ex As Exception
Throw ex

End Try
' Session("AddMode") = False
End Sub

Private Sub dgParents_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgParents.UpdateCommand
Dim strSQL As String
Dim strConnect As String
Dim strParentID As String

Dim strParentDesc As String
Dim dtEffectDate As String
Dim strRollupID As String
Dim strStructureID As String

Dim strConn As String
Dim dt As RobData.DataTransfer
Try
With e.Item
strParentID = CType(.Cells(0).Controls(0), TextBox).Text
strParentDesc = CType(.Cells(1).Controls(0), TextBox).Text
dtEffectDate = "2005-DEC-01" ' "to_date('" &
Format(CType(.Cells(2).Controls(0), TextBox).Text(), "yyyy-MMM-dd hh:mm:ss
tt") & "', 'yyyy/mm/dd:hh:mi:ssam')"
strRollupID = CType(.Cells(3).Controls(1),
DropDownList).SelectedItem.Value
strStructureID = CType(.Cells(4).Controls(1),
DropDownList).SelectedItem.Value
End With

strConn = dt.OracleConnect("rptpr01", "rptuser", "r00ster")
strSQL = String.Format("Update rlup_parent set ParentDesc =
'{0}', EFFDT = '{1}', RollupID = '{2}', structureid = '{3}' where parentid
= '{4}'", strParentDesc, dtEffectDate, strRollupID, strStructureID,
strParentID)
dt.ExecuteSQL(strSQL, strConn)

dgParents.EditItemIndex = -1
FillDataGrid_Parent_Filter(ucStructureRollupDropDo wn.StructureValue,
ucStructureRollupDropDown.RollupValue)

Catch ex As Exception
Throw ex

End Try
End Sub
Private Sub ddlStructure_BindData(ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)
Try
Dim strConn As String
Dim strSQL As String
Dim dt As New RobData.DataTransfer
Dim drStructure As OleDb.OleDbDataReader
Dim structItem As New ListItem

If e.Item.ItemType = ListItemType.EditItem Then
'Code to get the structure type
strConn = dt.OracleConnect("rptpr01", "rptuser", "r00ster")
strSQL = String.Format("SELECT * from RLUP_structureType")
drStructure = dt.GetDataReader(strSQL, strConn)
Dim DRV As DataRowView = CType(e.Item.DataItem, DataRowView)

Dim strStructureSelection As String = DRV("structuredesc")

Dim ddlStruct As New DropDownList

ddlStruct = CType(e.Item.FindControl("ddlStructureEdit"),
DropDownList)
Do While drStructure.Read 'Fills the drop down list box
structItem = New
ListItem(drStructure("structuredesc").ToString,
drStructure("structureID").ToString)
ddlStruct.Items.Add(structItem)
Loop
Dim itemStructure As New ListItem

itemStructure =
ddlStruct.Items.FindByText(strStructureSelection)
itemStructure.Selected = True
drStructure.Close()

End If

Catch ex As Exception
Throw ex
End Try
End Sub

Private Sub ddlRollup_BindData(ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)
Try
If e.Item.ItemType = ListItemType.EditItem Then
Dim strConn As String
Dim strSQL As String
Dim dt As New RobData.DataTransfer
Dim drRollup As OleDb.OleDbDataReader
Dim drStructure As OleDb.OleDbDataReader
Dim rollupItem As New ListItem

'Code to get the rollup type
strConn = dt.OracleConnect("rptpr01", "rptuser", "r00ster")
strSQL = String.Format("SELECT * from RLUP_RollupType")
drRollup = dt.GetDataReader(strSQL, strConn)

Dim DRV As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim strRollupSelection As String = DRV("rollupdesc")

Dim ddlRollup As New DropDownList
ddlRollup = CType(e.Item.FindControl("ddlRollupEdit"),
DropDownList)

Do While drRollup.Read 'Fills the drop down list box
rollupItem = New
ListItem(drRollup("RollupDesc").ToString, drRollup("RollupID").ToString)
ddlRollup.Items.Add(rollupItem)
Loop

Dim item As New ListItem

item = ddlRollup.Items.FindByText(strRollupSelection)
item.Selected = True
drRollup.Close()

End If

Catch ex As Exception
Throw ex
End Try

End Sub

Private Sub dgParents_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgParents.ItemDataBound

Try

If e.Item.ItemType = ListItemType.EditItem Then
ddlStructure_BindData(e)
ddlRollup_BindData(e)
End If

Catch ex As Exception
Throw ex
End Try
End Sub
End Class


"Darren Kopp" <da******************@gmail.com> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
You could always do ViewState["FilterVar1"] = "accounting" or something
similar if you didn't want to do session. Some code might help as your
problem could be in several areas (i'm guessing it's a re-binding problem).
-Darren Kopp
http://blog.secudocs.com

"Gummy" <gu***@nowhere.com> wrote in message
news:11*************@corp.supernews.com...
Hello All,

I have a webpage that has two dropdown listboxes. Based on what is
selected
in these dropdown listboxes, it filters a DataGrid . That works fine.

In the DataGrid , when I go to edit a row, I change the textbox (or other control), click Update, but it doesn't save my data. I then did this...

In Page_Load, I added code to filter the DataGrid only when it was Not
Page.IsPostBack. Then the editing/updating of the DataGrid data works
fine.
But, of course, I lose the ability to filter the DataGrid.

Obviously the problem is with the Postback. But how am I able to have both the postback and the editing available simultaneously?

I had heard that I should stay away from Session variables, but that seems that it might work here. Is there another way to do this without Session
variables?

Thank you for the help.


Jan 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jan Keller | last post by:
Hello all, I am using an XmlTextReader and a DataSet to populate a DataGrid: ds = New DataSet xr = New XmlTextReader(path) ds.ReadXml(xr) xr.Close() dv = New DataView(ds.Tables.Item(0))
1
by: sandman | last post by:
I've got a simple windows form with some bound textboxes and Save button. Each texbox is bound to column in a table in an Access database. The form fills fine - all the fields show the correct...
3
by: Rameshika | last post by:
Hi All How can I select a particular row in a datagrid.Where when the user double clicks the data in that row should appear in the corresponding text boxes in runtime And how can the user...
11
by: Brian W | last post by:
Yet another editor problem To reproduce do the following 1) Open a Webform and switch to HTML edit mode 2) Enter the Following (include spaces) This is some text before <asp:hyperlink...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
5
by: IGotYourDotNet | last post by:
I'm pulling data out of an oracle db and populating a datagrid such as this cars doors Cylinders chevy 4 6 ford 2 8 how can i make it such as cars ...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
6
by: needin4mation | last post by:
I have a set of textboxes. If it is a new record the textboxes are empty and there is a save button. If this is an existing record, I have a search form, a datagrid and the user selects form the...
3
by: Young J. Putt | last post by:
I have a vb.net datagrid bound to a dataview on a windows form. I want to use the datagrid to display and filter a list of items, but since the data is complex, I don't want the user to edit the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.