datagrid filtering/sorting problem seemingly impossible to solve

abstract1977

New member
Joined
Jun 13, 2003
Messages
2
Hello,

This is my last attempt to somehow get a solution to my
problem. Ive been working on this for quite some time now
also posting a number of messages in about a million
forums w/o any luck. Ill try to be as detailed as
possible..

Im building my pages in vstud.net latest version and Ive
followed learnvisualstudio.nets 3420 video on creating a
master/detail app. I have 2 datagrids on my page as well
as a number of textboxes and labels between them. The top
datagrid displays the main items, the newsitems. When
selecting one of those items its details show up in the
different textboxes below, and if there are any images
related to that specific newsitem I display those in the
second datagrid.

Just looking at the first datagrid with the newsitems in
it, paging works as well as selecting, deleting, updating
records.

As for the bottom datagrid with the newsitems
imagedetails in it, its not working as it should. Well, I
implemented the select, delete & update methods which are
working fine. The PROBLEM is this: My "image"-datagrids
properties are set in vstud.net and are as follows:


<asp:datagrid id=DataGrid2

style="Z-INDEX: 124; LEFT: 23px; POSITION: absolute; TOP:
1100px"

runat="server"

Width="821px"

Height="348px"

DataSource="<%# DsAdminNyheter1 %>"

DataMember="Bilder"

DataKeyField="BilderID"

AutoGenerateColumns="False"

BorderColor="White"

BorderStyle="None"

BorderWidth="0px"

BackColor="White"

CellPadding="3"

GridLines="None"

CellSpacing="1"

Font-Names="Verdana"

Font-Size="X-Small"

OnUpdateCommand="datagrid2_UpdateCommand"
OnCancelCommand="datagrid2_CancelCommand"
OnEditCommand="datagrid2_EditCommand">

..

..

..etc.

</asp:datagrid>

Although, when the user has selected a newsitem i conduct
the following:

Sub UpdateDetails_Bilder()

DsAdminNyheter1 = Session("dsNyheter")

Dim strKriteria As String

strKriteria = "NyheterID=" & lblNyhetID.Text

Dim dt As DataTable

Dim dr As DataRow()

dt = DsAdminNyheter1.Tables("Bilder")

dr = dt.Select(strKriteria)
Dim dvBilder As New DataView(dt)
dvBilder.RowFilter = strKriteria

Dim dr As DataRow()
dr = dt.Select(strKriteria)

If dvBilder.Count > 0 Then

DataGrid2.Visible = True

DataGrid2.DataSource = dvBilder

DataGrid2.DataBind()

Else

DataGrid2.Visible = False

End If

Session.Add("dsNyheter", DsAdminNyheter1)

End Sub

This should as far as I can see and have read in a number
of places work. But it doesnt. For some reason there is
no filtering at all. The datagrid simply displays the
contents of the entire "Bilder"-table. I have even tried
setting the datagrids datasource to a
command.executereader where I know for a fact it shouldnt
return all records. NOTHING WORKS!

I think that the problem lies in saving the dataset in the
session object somehow, and the lines of Session.add and
dsadminnyheter1 = Session("dsNyheter") are a relic of the
video I used as a frame for the page; problem is that I
have not yet quite grasped exactly how it works...

Thats why I think that the SECOND problem which is that
when I try to implement a sorting method for the first
datagrid, suffers the same fate. This method is also based
on using a dataview and sorting it to then setting the
datagrid1.datasource = sorted dataview. This operation
does not affect the order of anything in my datagrid.


This is my page_load routine:

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load


If Not Page.IsPostBack Then

OleDbConnection2.Open()

OleDbDataAdapter1.Fill
(DsAdminNyheter1, "Nyheter")

OleDbDataAdapter2.Fill
(DsAdminNyheter1, "Bilder")

OleDbDataAdapter3.Fill
(DsAdminNyheter1, "L
 
Try to delete this line:

DataSource="<%# DsAdminNyheter1 %>"

because you are lately setting this datasource to dataview:

Code:
DataGrid2.DataSource = dvBilder
DataGrid2.DataBind()

and probably DataBinds binds your grid to DsAdminNyheter1, not to dvBilder
 
Problem solved!

THANK YOU!

I guess Im not good enough with Vstud.net that I can use the designer to set the datagrid properties as well as bindning new data to it runtime.

You were absolutely right that no matter what I set the datagrids datasource to in my code behind, it was whatever the vstud designer had put in my .aspx code that determined what data was to be displayed.

Anyway, thanks for putting an end to a week long mindbender.


/Olof
 
Back
Top