Reputation: 21
I got a function to which I provide an ID, which, in turn, returns a collection of results.
From these, I get yet another set of results, that I display in a datagrid.
With the code below I get the results from the Last Node that has Notes.
private void GetNotesList(int Id)
{
DataAccess.LexCodeNode LexCodeNode = new DataAccess.LexCodeNode();
LexCodeNode.Where.LexCodeId.Value = Id;
LexCodeNode.Query.Load();
for (int Index = 0; Index <= LexCodeNode.RowCount; Index++, LexCodeNode.MoveNext())
{
int LexCodeNodeId = LexCodeNode.LexCodeNodeId;
DataAccess.LexCodeNote LexCodeNote = new DataAccess.LexCodeNote();
LexCodeNote.Where.LexCodeNodeId.Value = LexCodeNodeId;
if (LexCodeNote.Query.Load())
{
BindGrid(DgNoteLst, LexCodeNote.DefaultView);
}
}
}
I know I should do something like
Array Notes = new Array();
for (int Index = 0; Index <= LexCodeNode.RowCount; Index++, LexCodeNode.MoveNext())
{
int LexCodeNodeId = LexCodeNode.LexCodeNodeId;
DataAccess.LexCodeNote LexCodeNote = new DataAccess.LexCodeNote();
LexCodeNote.Where.LexCodeNodeId.Value = LexCodeNodeId;
if (LexCodeNote.Query.Load())
{
Notes.Add(LexCodeNote);
}
}
BindGrid(DgNoteLst, Notes); // I should send Notes as a View..
My question is: How do I add these values to the DefaulView from each cycle.
private void BindGrid(DataGrid grid, DataView view)
{
grid.DataSource = view;
grid.DataBind();
}
Upvotes: 0
Views: 38
Reputation: 21
I found another way..
I made a Stored Procedure to get what I needed and then call it.
USE [Table]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE Custom_GetNotesList(@LexCodeId int)
AS
BEGIN
Select LexCodeNodeId, Note, Active
From LexCodeNote
Where LexCodeNodeId in (
Select LexCodeNodeId
From LexCodeNode
where LexCodeId = @LexCodeId)
END
Here is how I call it.
private void GetNotesList(int Id, int Page)
{
DataAccess.LexCodeNode LexCodeNode = new DataAccess.LexCodeNode();
LexCodeNode.GetNotesList(Id);
BindGrid(DgNoteLst, LexCodeNode.DefaultView);
}
And the definition in the DataAccess Segment
public bool GetNotesList(int pLexCodeId)
{
ListDictionary parameters = new ListDictionary();
parameters.Add(Parameters.LexCodeId, pLexCodeId);
return base.LoadFromSql("[" + this.SchemaStoredProcedure + "Custom_GetNotesList]", parameters);
}
Upvotes: 0