Passing a value to a DataGrid
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngdatagridrepeaterdatalist' list.


Eric
I'm working on a DataGrid with paging. My SQL string is based on a
search term entered by the user 'strAbstract'. When I perform the first
search, the correct number of records are returned, but when I begin
paging through the DataSet, I lose my value for 'strAbstract' and I
begin paging through every record in the table. How do I retain or pass
my user-entered value for 'strAbstract' while paging? Thanks.

<script language="VB" runat="server">

Sub Page_Load
If Not isPostBack Then
BindDataGrid()
End If
End Sub

Sub BindDataGrid

Dim strAbstract As String = Context.Request.Form("Abstract")
Dim SqlText As String = "SELECT tblCatalog.CatalogID,
tblCatalog.Title, tblCatalog.Author, tblCatalog.Publication,
tblCatalog.DatePublished, tblCatalog.CopyrightYear, tblCatalog.Abstract
FROM tblCatalog WHERE ((tblCatalog.Title) Like '%")"

Dim ds As DataSet
Dim MyConnection As SqlConnection
Dim intRecordCount As Integer

MyConnection = New
SqlConnection("server=;database=CatalogSQL;uid=WebUser;password=")
Dim MyAdapter As New SqlDataAdapter(SqlText, MyConnection)

MyConnection.Open()

ds = new DataSet()
MyAdapter.Fill(ds, "Abstract")

dgAbstract.DataSource=ds.Tables("Abstract").DefaultView
dgAbstract.DataBind()

MyConnection.Close()

End Sub

Sub dgAbstract_PageIndexChanged(s As Object, e As
DataGridPageChangedEventArgs)
dgAbstract.CurrentPageIndex = e.NewPageIndex
BindDataGrid()
End Sub
</script>

<form runat="server">
<asp:DataGrid id="dgAbstract" runat="server"
AllowPaging="True"
PageSize="10"
OnPageIndexChanged="dgAbstract_PageIndexChanged"
PagerStyle-Mode="NumericPages"
PagerStyle-Font-Name="Verdana"
AutoGenerateColumns="False"

<Columns>

<asp:BoundColumn
DataField="CatalogID"
Visible="False" />

<asp:BoundColumn
DataField="Title"
HeaderText="Title" />

<asp:BoundColumn
DataField="Author"
HeaderText="Author" />

</Columns>
</asp:DataGrid>
</form>
Reply to this message...
 
    
Das
Best way is to have a Label Web Server Control with a visible property
set to "False". You can use this Label web server control to store any
value. Retrieving the value from the Label Web server control is also
very simple.

To know more about Label Web Server control, read this:
http://aspalliance.com/das/tutorial/label.aspx" target="_blank">http://aspalliance.com/das/tutorial/label.aspx

Want to start with ASP.NET, read my ASP.NET tutorial at
http://aspalliance.com/das/tutorial/default.aspx

:-)
Jesudas Chinnathampi (Das)

Co-Author - Beginning ASP.NET Databases using VB.NET
http://www.amazon.com/exec/obidos/ASIN/1861006195

Co-Author - Beginning ASP.NET Databases using C#
http://www.amazon.com/exec/obidos/ASIN/1861007418

Read my articles on ASP .NET at
http://aspalliance.com/das

----- Original Message -----
From: "Eric" <Click here to reveal e-mail address>
To: "aspngDataGridRepeaterDatalist"
<Click here to reveal e-mail address>
Sent: Wednesday, July 24, 2002 2:26 PM
Subject: [aspngdatagridrepeaterdatalist] Passing a value to a DataGrid

[Original message clipped]

Reply to this message...
 
    
Eric
ok, but how I do both retrieve the value from the other page and also
from the label control? I added the lines in bold. Thanks.

<script language="VB" runat="server">

Sub Page_Load
If Not isPostBack Then
BindDataGrid()
End If
End Sub

Sub BindDataGrid

Dim strAbstract As String = Context.Request.Form("Abstract")
Abstract.Text = strAbstract

Dim SqlText As String = "SELECT tblCatalog.CatalogID,
tblCatalog.Title, tblCatalog.Author, tblCatalog.Publication,
tblCatalog.DatePublished, tblCatalog.CopyrightYear, tblCatalog.Abstract
FROM tblCatalog WHERE ((tblCatalog.Title) Like '%" & strAbstract & "%')"

'Create Sqlconnection
'Create SqlAdapter
'Create and fill DataSet
'Bind to DataGrid

Sub dgAbstract_PageIndexChanged(s As Object, e As
DataGridPageChangedEventArgs)
dgAbstract.CurrentPageIndex = e.NewPageIndex
BindDataGrid()
End Sub

</script>

<form runat="server">
<asp:label id="Abstract" runat="server" />
<asp:DataGrid id="dgAbstract" runat="server" />
</form>

-----Original Message-----
From: Das [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 24, 2002 3:16 PM
To: aspngDataGridRepeaterDatalist
Subject: [aspngdatagridrepeaterdatalist] Re: Passing a value to a
DataGrid

Best way is to have a Label Web Server Control with a visible property
set to "False". You can use this Label web server control to store any
value. Retrieving the value from the Label Web server control is also
very simple.

To know more about Label Web Server control, read this:
http://aspalliance.com/das/tutorial/label.aspx" target="_blank">http://aspalliance.com/das/tutorial/label.aspx

Want to start with ASP.NET, read my ASP.NET tutorial at
http://aspalliance.com/das/tutorial/default.aspx

:-)
Jesudas Chinnathampi (Das)

Co-Author - Beginning ASP.NET Databases using VB.NET
http://www.amazon.com/exec/obidos/ASIN/1861006195

Co-Author - Beginning ASP.NET Databases using C#
http://www.amazon.com/exec/obidos/ASIN/1861007418

Read my articles on ASP .NET at
http://aspalliance.com/das

----- Original Message -----
From: "Eric" <Click here to reveal e-mail address>
To: "aspngDataGridRepeaterDatalist"
<Click here to reveal e-mail address>
Sent: Wednesday, July 24, 2002 2:26 PM
Subject: [aspngdatagridrepeaterdatalist] Passing a value to a DataGrid

[Original message clipped]

| [aspngdatagridrepeaterdatalist] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngdatagridrepeaterdatalist.asp
| = JOIN/QUIT
Reply to this message...
 
 
System.Data.DataSet
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.Runtime.Remoting.Contexts.Context
System.Web.UI.MobileControls.PagerStyle
System.Web.UI.WebControls.BoundColumn
System.Web.UI.WebControls.DataGrid
System.Web.UI.WebControls.DataGridPageChangedEventArgs
System.Windows.Forms.DataGrid




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com