Datagrid does not respond to any sorting, dataview filtering, or paging events

M

Michelle

This is my third VB.NET forum to try and help me with my problems and several people have failed so I am hoping someone here is a TRUE GURU on datagrids!

I have a datagrid that I bind to a datasource in the page_load event. No problem.
However, when I try to do ANYTHING to its data, nothing works.

Problem 1)

When clicking a dropdown I try to create a dataview based on the value the user selected in the DD and have the filter based on that value....Here is the code.....


Private Sub ddPQMSGrp_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddPQMSGrp.SelectedIndexChanged

Dim strSvcValue As String
strSvcValue = ddPQMSGrp.SelectedItem.Text

Dim dv As New DataView(DataSet151.Tables("Products"))
dv.Table = DataSet151.Products
dv.RowFilter = "[ItemCode (SAP)] = 'strSvcValue'"
DataGridProd.DataSource = dv
DataGridProd.DataBind()

My dataview finds no records matching my filter criteria (which I know exists in the table and the debugger shows that my variable 'strSvcValue' contains the correct value)

Problem 2)
The datagrids property is set to Allow Sorting. My code is as follows...

Private Sub DataGridProd_SortCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs)
DataGridProd.DataSource = DataSet151.Products.DefaultView
DataSet151.Products.DefaultView.Sort = e.SortExpression
DataGridProd.DataBind()
End Sub

Nothing happens to the datagrid...the data does not change.

Problem 3)
I cannot click on the numbers at the bottom of the datagrid to page through the records. I have the AllowPaging set to true and have selected 30 records to display on each page. My code is as follows.....

Private Sub DataGridProd_PageIndexChanged(ByVal source As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
DataGridProd.CurrentPageIndex = e.NewPageIndex
DataGridProd.DataBind()

End Sub

The data on the datagrid does not change.

Someone, please help me. All of my code basically comes from MS tutorials, my ASP.net class, the Visual Studio help files with sample code, etc. I have even tried using different tables and different databases but every datagrid acts the same (eg, no changes allowed!!) I"M CONSIDERING A SMALL REWARD FOR THE PERSON WHO CAN HELP ME:)

From http://www.developmentnow.com/g/12_2005_2_0_0_0/dotnet-framework-aspnet-datagridcontrol.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
E

Elton Wang

Hi Michelle,

About your Questions:

Problem 1)

Change
dv.RowFilter = "[ItemCode (SAP)] = 'strSvcValue'"
to
dv.RowFilter = "[ItemCode (SAP)] = '" + strSvcValue + "'"

Problem 2)

You can try
Dim dv As DataView = DataSet151.Tables
("Products").DefaultView
dv.Sort = e.SortExpression
DataGridProd.DataSource = dv
DataGridProd.DataBind()


Problem 3)

What do you mean 'cannot click on the numbers'?

Anywany, code should be

DataGridProd.CurrentPageIndex = e.NewPageIndex
DataGridProd.DataSource = yourDataSource
DataGridProd.DataBind()

HTH

Elton Wang
(e-mail address removed)

-----Original Message-----
This is my third VB.NET forum to try and help me with my
problems and several people have failed so I am hoping
someone here is a TRUE GURU on datagrids!
I have a datagrid that I bind to a datasource in the page_load event. No problem.
However, when I try to do ANYTHING to its data, nothing works.

Problem 1)

When clicking a dropdown I try to create a dataview based
on the value the user selected in the DD and have the
filter based on that value....Here is the code.....
Private Sub ddPQMSGrp_SelectedIndexChanged(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
ddPQMSGrp.SelectedIndexChanged
Dim strSvcValue As String
strSvcValue = ddPQMSGrp.SelectedItem.Text

Dim dv As New DataView(DataSet151.Tables ("Products"))
dv.Table = DataSet151.Products
dv.RowFilter = "[ItemCode (SAP)] = 'strSvcValue'"
DataGridProd.DataSource = dv
DataGridProd.DataBind()

My dataview finds no records matching my filter criteria
(which I know exists in the table and the debugger shows
that my variable 'strSvcValue' contains the correct value)
Problem 2)
The datagrids property is set to Allow Sorting. My code is as follows...

Private Sub DataGridProd_SortCommand(ByVal source As
System.Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEventArgs)
DataGridProd.DataSource = DataSet151.Products.DefaultView
DataSet151.Products.DefaultView.Sort = e.SortExpression
DataGridProd.DataBind()
End Sub

Nothing happens to the datagrid...the data does not change.

Problem 3)
I cannot click on the numbers at the bottom of the
datagrid to page through the records. I have the
AllowPaging set to true and have selected 30 records to
display on each page. My code is as follows.....
Private Sub DataGridProd_PageIndexChanged(ByVal source As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
DataGridProd.CurrentPageIndex = e.NewPageIndex
DataGridProd.DataBind()

End Sub

The data on the datagrid does not change.

Someone, please help me. All of my code basically comes
from MS tutorials, my ASP.net class, the Visual Studio
help files with sample code, etc. I have even tried using
different tables and different databases but every
datagrid acts the same (eg, no changes allowed!!) I"M
CONSIDERING A SMALL REWARD FOR THE PERSON WHO CAN HELP ME:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top