 |
| ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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
|
|
|
|

March 24th, 2006, 07:29 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to add to datagrid without database
Hi,
I have to add details to a datagrid. but each time the submit clicked, the the page refreshes and the previous entered detail to the datagrid is lost. there is no database to save the datagrid. how do i save the details without database or just refresh the grid without postback the page?
Thanks.
annsary
|
|

March 24th, 2006, 09:59 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hii annsary!!
You can use cache object to save data,and add it new reqd items and then bind it to data grids :)
Hope this will help you.
Cheers :)
vinod
|
|

March 24th, 2006, 02:53 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Add your info into a data table, then rebind on postback.
|
|

March 28th, 2006, 06:06 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Vinod,
Thanks for your suggestion. used session to save the datatable. is cache better or session or cookie better?
jbenson001,
there is no database to insert. the program is to list user entered info and extract info for each row from a read access database.
thanks.
regards,
annsary
|
|

March 28th, 2006, 10:45 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
I said data table, not database
|
|

March 28th, 2006, 08:43 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi jbenson001,
oops sorry. tried that method. but the data table becomes empty when postback. :(
|
|

March 29th, 2006, 12:14 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
did you put the code in an if statment?:
If NOT IsPagePostBack Then
..Fill data table
End IF
|
|

March 30th, 2006, 12:19 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
the datagrid will be empty when the page is first loaded. only after the user enters the data and click the add button, the data is added to the datagrid.
the datatable becomes empty at postback. the datatable is showing as 'Nothing'. all data entries before post back is lost. so how to fill?
By using the following code, I am able to add. prefer not to use session/cache/cookie as consume server resource and have to do more maitenance:
If Not IsPostBack Then
Bindgrd()
Else
If Session(SesDs) Is Nothing Then
Else
dsTag = CType(Session(SesDs), DataSet)
dt = ds.Tables(sTbl)
End If
End If
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
Session(SesDs) = ds
End Sub
Private Sub bAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tRow As DataRow
Dim itmArr() As Object = {tText1.Text, tText2.Text, tText3.Text}
tRow = dt.NewRow()
tRow.ItemArray = itmArr
dt.Rows.Add(tRow)
ds.Tables.Add(dt)
Bindgrd()
End Sub
Private Sub Bindgrd()
gdataGrid.DataSource = ds
gdataGrid.DataBind()
gdataGrid.Visible = True
End Sub
|
|

March 30th, 2006, 12:58 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Once the click of the button click, you do not put your data set into the session variable. Add:
Session(SesDs) = ds BEFORE the call to Bindgrd().
Not sure why you have Session(SesDs) = ds in prerender event. Seems like that will overwrite ds. And where is ds declared?
|
|

March 30th, 2006, 01:44 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
added Session(SesDs) = ds in the PreRender as this function will be called before page is rendered.
ds is declared in the Page's class section.
Public Class clUserData
Inherits System.Web.UI.Page
Dim ds As DataSet
Dim dt As DataTable
annsary
|
|
 |