Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need keywords

Status
Not open for further replies.

hockeylvr

Technical User
Nov 26, 2002
140
I'm sure the answer to my question is in the forum somewhere but I can't figure out what I should be looking for. I have a page with a drop down list (DropDownList1)
and a Select button. When the item is selected from the ddl DataGrid1 appears with the appropriate data. The first column of the data grid is a hyperlink which goes to a details page (details.aspx)for viewing only.

I want the user to be able to click on the "Home" button on details.aspx and have DataGrid1 have remained on the first page and still populated with the selections so the user can select another item for viewing.

Right now the DataGrid1 disappears on return to the home page.

Am I looking for SessionState, ApplicationState??

Thanks!


 
You can easily pass a variable between 2 or more pages using Request.Querystring.

For example...

You have a datagrid hyperlink column which directs the user to home.aspx...
NavigateURL="home.aspx"

You have a datagrid hyperlink column which directs the user to home.aspx, and also passes the value "ID" from the datagrid...
NavigateURL='<%# "home.aspx?id=" & DataBinder.Eval(Container, "DataItem.id")%>'


Then, let's say on home.aspx you have a datagrid which should be bound based on the value of "id". You can say something like...

If Request.QueryString.Has Keys Then ' Check for the presence of a passed variable in the Request.QueryString
Me.datagrid1.Datasource = Request.Querystring("id")
Me.datagrid.DataBind.

For more info on this topic, look at this link...

--
Regards,
Mike
 
Thanks Mike,

I placed this code in my Page Load for my main page:

Sub Page_Load

If Page.IsPostBack Then
If Request.QueryString.HasKeys
Me.DataGrid1.Datasource = Request.Querystring ("supplierid")
Me.DataGrid1.DataBind()
End If
End If
End Sub

Here is the code that populates the datagrid when an item is selected in the ddl:


Function GetSupplierDetails(ByVal producttype As String) As System.Data.DataSet
Dim connectionString As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;" & _
"Data Source=" & HttpContext.Current.Server.MapPath("data/AcquiredProducts.mdb"))


Dim QueryString As String = "SELECT [AcquiredProducts].[supplierid],[AcquiredProducts].[supplier], [AcquiredProducts].[suppliernumber], [AcquiredProducts].[producttype]FROM [AcquiredProducts] WHERE ([AcquiredProducts].[prod"& _
"ucttype] = @producttype)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = QueryString
dbCommand.Connection = connectionString

Dim dbParam_producttype As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_producttype.ParameterName = "@producttype"
dbParam_producttype.Value = producttype
dbParam_producttype.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_producttype)

Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function




It doesn't seem to be working-I'm not getting an error msg, just works the same way.

I'm having no problems displaying the detail data on my 2nd page which is linked to supplierid, I just can't get the Data Grid on the first page to remain populated on return to it from the 2nd page.

I thought "Enabling View State" would do it, but nothing happens.

Thanks for your help.

Toni
 
Mike,

No, only the website address appears in the address bar.

If I return to page 1 using the browser's "Back" button, the datagrid remains visible and populated, but not when I use my "Home" button. Does that make sense?

The address bar remains the same either way.

I'm looking at how to rebind the datagrid on postback - does that sound like the direction I need to go?

Thanks,

Toni
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top