|
Rank: Member Groups: Member
Joined: 7/13/2011 Posts: 13
|
I am unable to populate a grid with an IDataReader class
my test iDataReader produces 4 rows of data, but the grid shows just the row number column, with all other cells being blank
Please help.
Here is the code I use to populate the grid =============================== iRecordCount = Load_TestEOList(); TestEOGrid.DataSource = TestReader; TestEOGrid.RecordCount = iRecordCount; TestEOGrid.DataBind(); ===============================
Here is the grid itself from the aspx page <eo:Grid ID="TestEOGrid" runat="server" BorderColor="Black" BorderWidth="1px" ColumnHeaderAscImage="00050403" ColumnHeaderDescImage="00050404" ColumnHeaderDividerImage="00050402" ColumnHeaderDividerOffset="6" ColumnHeaderHeight="18" DataTable="" FixedColumnCount="1" Font-Bold="False" Font-Italic="False" Font-Names="Verdana" Font-Overline="False" Font-Size="9pt" Font-Strikeout="False" Font-Underline="False" GridLineColor="240, 240, 240" GridLines="Both" Height="200px" ItemHeight="18" Width="380px"> <FooterStyle CssText="padding-bottom:4px;padding-left:4px;padding-right:4px;padding-top:4px;" /> <ColumnTemplates> <eo:TextBoxColumn> <TextBoxStyle CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 8.75pt; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; FONT-FAMILY: Tahoma" /> </eo:TextBoxColumn> <eo:DateTimeColumn> <DatePicker ControlSkinID="None" DayCellHeight="16" DayCellWidth="19" DayHeaderFormat="FirstLetter" DisabledDates="" OtherMonthDayVisible="True" SelectedDates="" TitleLeftArrowImageUrl="DefaultSubMenuIconRTL" TitleRightArrowImageUrl="DefaultSubMenuIcon"> <TodayStyle CssText="font-family: tahoma; font-size: 12px; border-right: #bb5503 1px solid; border-top: #bb5503 1px solid; border-left: #bb5503 1px solid; border-bottom: #bb5503 1px solid" /> <SelectedDayStyle CssText="font-family: tahoma; font-size: 12px; background-color: #fbe694; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" /> <DisabledDayStyle CssText="font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" /> <PickerStyle CssText="border-bottom-color:#7f9db9;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#7f9db9;border-left-style:solid;border-left-width:1px;border-right-color:#7f9db9;border-right-style:solid;border-right-width:1px;border-top-color:#7f9db9;border-top-style:solid;border-top-width:1px;font-family:Courier New;font-size:8pt;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;padding-bottom:1px;padding-left:2px;padding-right:2px;padding-top:2px;" /> <CalendarStyle CssText="background-color: white; border-right: #7f9db9 1px solid; padding-right: 4px; border-top: #7f9db9 1px solid; padding-left: 4px; font-size: 9px; padding-bottom: 4px; border-left: #7f9db9 1px solid; padding-top: 4px; border-bottom: #7f9db9 1px solid; font-family: tahoma" /> <TitleArrowStyle CssText="cursor:hand" /> <DayHoverStyle CssText="font-family: tahoma; font-size: 12px; border-right: #fbe694 1px solid; border-top: #fbe694 1px solid; border-left: #fbe694 1px solid; border-bottom: #fbe694 1px solid" /> <MonthStyle CssText="font-family: tahoma; font-size: 12px; margin-left: 14px; cursor: hand; margin-right: 14px" /> <TitleStyle CssText="background-color:#9ebef5;font-family:Tahoma;font-size:12px;padding-bottom:2px;padding-left:6px;padding-right:6px;padding-top:2px;" /> <OtherMonthDayStyle CssText="font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" /> <DayHeaderStyle CssText="font-family: tahoma; font-size: 12px; border-bottom: #aca899 1px solid" /> <DayStyle CssText="font-family: tahoma; font-size: 12px; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" /> </DatePicker> </eo:DateTimeColumn> <eo:MaskedEditColumn> <MaskedEdit ControlSkinID="None" TextBoxStyle-CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; font-family:Courier New;font-size:8pt;"> </MaskedEdit> </eo:MaskedEditColumn> </ColumnTemplates> <ColumnHeaderStyle CssText="background-image:url('00050401');padding-left:8px;padding-top:2px;" /> <ItemStyles> <eo:GridItemStyleSet> <ItemStyle CssText="background-color: white" /> <CellStyle CssText="padding-left:8px;padding-top:2px; color:#black;white-space:nowrap;" /> </eo:GridItemStyleSet> </ItemStyles> <Columns> <eo:RowNumberColumn AllowResize="False" Width="20"> </eo:RowNumberColumn> <eo:StaticColumn HeaderText="Field1" Name="Field1"> </eo:StaticColumn> <eo:StaticColumn HeaderText="Field2" Name="Field2"> </eo:StaticColumn> </Columns> </eo:Grid> ===============================
Here is the code for TestListReader =============================== using System; using System.Data; using System.Collections; using System.Collections.Specialized;
namespace TheUncorkedCellar { public class TestListReader : IDataReader { public static IDataReader GetReader() { return GetReader("."); }
public static IDataReader GetReader( string sSourceName ) { return new TestListReader(sSourceName); }
private object[,] _RecordTable; private int _iCurrentRecord = -1; private int _iRecordCount;
// Models a list // as if it were a table that contained // rows of the following name/position: // // Field1, Field2, Field3 // private static string[] _sColumnNames = { "Field1", "Field2", "Field3" };
internal TestListReader() : this(".") { }
internal TestListReader(string sSourceName) { // Process[] procList = Process.GetProcesses(sSourceName); //_iRecordCount = procList.Length;
_iRecordCount = 4;
_RecordTable = new object[_iRecordCount, _sColumnNames.Length];
//Generate a dummy table with the following values // Row Field1 Field2 Field3 // 1 1A 1B 1C // 2 2A 2B 2C // 3 3A 3B 3C // 4 4A 4B 4C
for (int row = 0; row < _iRecordCount; row++) { _RecordTable[row, 0] = row.ToString() + 'A'; _RecordTable[row, 1] = row.ToString() + 'B'; _RecordTable[row, 2] = row.ToString() + 'C'; } }
// IDispose public void Dispose() { // Not holding any external resources. }
// IDataRecord // public int FieldCount { get { if( (0 <= _iCurrentRecord) && (_iCurrentRecord < _iRecordCount) ) { return(_sColumnNames.Length); }
return(0); } }
public object this[ string colName ] { get { if( (_iCurrentRecord < 0) || (_iCurrentRecord >= _iRecordCount) ) { throw new IndexOutOfRangeException("Record cursor position"); }
int colIndex = IndexOfCol(colName);
if( colIndex == -1 ) { throw new ArgumentException(string.Format("Invalid column name ({0})", colName), "colName"); }
return(_RecordTable[_iCurrentRecord,colIndex]); } }
public object this[ int colIndex ] { get { if( (_iCurrentRecord < 0) || (_iCurrentRecord >= _iRecordCount) ) { throw new IndexOutOfRangeException("Record cursor position"); }
if( (colIndex < 0) || (colIndex >= _sColumnNames.Length) ) { throw new ArgumentException(string.Format("Invalid column index ({0})", colIndex), "colIndex"); }
return(_RecordTable[_iCurrentRecord,colIndex]); } }
public bool GetBoolean( int i ) { throw new NotImplementedException("TestListReader.GetBoolean"); }
public byte GetByte( int i ) { throw new NotImplementedException("TestListReader.GetByte"); }
public long GetBytes( int i, long fieldOffset, byte[] buffer, int bufferOffset, int length ) { throw new NotImplementedException("TestListReader.GetBytes"); }
public char GetChar( int i ) { throw new NotImplementedException("TestListReader.GetChar"); }
public long GetChars( int i, long fieldOffset, char[] buffer, int bufferOffset, int length ) { throw new NotImplementedException("TestListReader.GetChars"); }
public IDataReader GetData( int i ) { throw new NotImplementedException("TestListReader.GetData"); }
public string GetDataTypeName( int i ) { // In real life, this would probably be implemented // to return type names that match standard database // type names. ??? // return(GetFieldType(i).Name); }
public DateTime GetDateTime( int i ) { throw new NotImplementedException("TestListReader.GetDateTime"); }
public decimal GetDecimal( int i ) { throw new NotImplementedException("TestListReader.GetDecimal"); }
public double GetDouble( int i ) { throw new NotImplementedException("TestListReader.GetDouble"); }
public Type GetFieldType( int i ) { if( (_iCurrentRecord < 0) || (_iCurrentRecord >= _iRecordCount) ) { throw new IndexOutOfRangeException("Record cursor position"); }
if( (i < 0) || (i > _sColumnNames.Length) ) { throw new IndexOutOfRangeException("Field index"); }
return(_RecordTable[_iCurrentRecord,i].GetType()); }
public float GetFloat( int i ) { throw new NotImplementedException("TestListReader.GetFloat"); }
public Guid GetGuid( int i ) { throw new NotImplementedException("TestListReader.GetGuid"); }
public short GetInt16( int i ) { throw new NotImplementedException("TestListReader.GetInt16"); }
public int GetInt32( int i ) { throw new NotImplementedException("TestListReader.GetInt32"); }
public long GetInt64( int i ) { throw new NotImplementedException("TestListReader.GetInt64"); }
public string GetName( int i ) { if( i < _sColumnNames.Length ) { return(_sColumnNames[i]); }
throw new IndexOutOfRangeException(string.Format("Specified column index is invalid ({0})", i)); }
public int GetOrdinal( string colName ) { int colIndex = IndexOfCol(colName);
if( colIndex != -1 ) { return(colIndex); }
throw new ArgumentException("Invalid column name specified.", "colName"); }
public string GetString( int i ) { throw new NotImplementedException("TestListReader.GetString"); }
public object GetValue( int i ) { throw new NotImplementedException("TestListReader.GetValue"); }
public int GetValues( object[] values ) { throw new NotImplementedException("TestListReader.GetValues"); }
public bool IsDBNull( int i ) { return(false); }
// IDataReader // public int Depth { get { return(0); } }
public bool IsClosed { get { return(true); } }
public int RecordsAffected { get { return(0); } }
public void Close() { }
public DataTable GetSchemaTable() { throw new NotImplementedException("TestListReader.GetSchemaTable"); }
public bool NextResult() { if( _iCurrentRecord < (_iRecordCount - 1) ) { _iCurrentRecord++; return(true); }
return(false); }
public bool Read() { return NextResult(); }
// Implementation support. // private int IndexOfCol( string colName ) { for( int n = 0; n < _sColumnNames.Length; n++ ) { if( _sColumnNames[n] == colName ) { return(n); } }
return(-1); } } }
=============================== I have also tried with a similar test that successfully binds a custom datasource to a standard grid but it does not work either
Thanks in advance for your help Brian
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
You must also implement IDataRecord interface. For all the IDataRecord methods, you only need to implement this[string fieldName]. That's the one that we use to get the field value.
Alternatively, you can also implement a property with the same name as your field name. For example, if your column's DataField is set to "Field0", then you can implement a "Field0" property on your TestListReader object that returns the value of "Field0" for the current record.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 7/13/2011 Posts: 13
|
Sorry to show my ignorance - I'm new to asp.net (and lost)
Can you provide some sample code please showing how to add an iDataRecord interface?.. (I've searched the web hi and low and cannot find any examples I can follow.
I had thought that by providing the following code for "this" within the TestListReader that I it provided the iDateRecord interface.... but obviously not. I tried adding a "Field1" function to the class, but that did not work and was never called.
Thanks for your help Brian
====================== public object this[ string colName ] { get { if( (_iCurrentRecord < 0) || (_iCurrentRecord >= _iRecordCount) ) { throw new IndexOutOfRangeException("Record cursor position"); }
int colIndex = IndexOfCol(colName);
if( colIndex == -1 ) { throw new ArgumentException(string.Format("Invalid column name ({0})", colName), "colName"); }
return(_RecordTable[_iCurrentRecord,colIndex]); } } ======================
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Your code looks fine. What's the problem?
If you use Visual Studio, the easiest way is to type somethign like this:
TestListReader: your_other_interfaces, IDataRecord { }
Then right click on IDataRecord and select "Implement Interface".
Thanks
|
|
Rank: Member Groups: Member
Joined: 7/13/2011 Posts: 13
|
The problem is the grid is always blank other than row numbers in the 1st column. (I cannot work out how to populate it) I have extracted the relevent code to seperate files so there is only the EO Grid related test code and uploaded them to www.my-uncork.com/EO.zipThanks for the step of adding ", iDataRecord" to my class definition, but it did not solve the problem. When I right-click on iDataReader gives a menu item to "Implement Interface" but not if I right-click on iDataRecord ( it seems I already have them all anyway) I am running VS 2008, targeting asp.net 3.5 Thanks for your help, Brian
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
We are not really supposed to troubleshoot simple coding issues like this for you. : ) You need to implement IDataRecord.this[string name]. That's the function we call and that's the whole point of you implementing that interface. In your case you have "throw new NotImplementedException();" in your implementation. When you have that in every of your IDataRecord's interface member then you are not implementing anything at all.
Thanks
|
|
Rank: Member Groups: Member
Joined: 7/13/2011 Posts: 13
|
Please accept my apologies- I had not noticed the extra templates added - I guess by the right-click Unfortunately, I think my problem is more than a coding issue (I was able to get a standard grid to populate quite easily, but feel like I am hitting my head against a brick wall with EO's grid ) I have added extra code to implement every called interface - see www.my-uncork.com/EO.zipAdding a break to every function in the testlistreader class, the following are the ONLY calls which triggered a break IDataReader GetReader() TestListReader(string sSourceName) IDataReader.Read() IDataReader.Read() IDataReader.Read() IDataReader.Read() IDataReader.Read() IDataReader.Read() //ie: called once per record plus 1 .. then nothing - no sign of any call to Field1, Field2 or IDataRecord.this[string name] I increased _iRecordCount to 5 - proving I can at least affect how many rows the grid holds - but they are all blank :-( You can see the result in result.jpg and the code for the class in TestListReader.cs Thanks again for your help Brian
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, Please change your column definition from:
Code: HTML/ASPX
<eo:StaticColumn HeaderText="Field 1" Name="Field1">
</eo:StaticColumn>
To:
Code: HTML/ASPX
<eo:StaticColumn HeaderText="Field 1" DataField="Field1">
</eo:StaticColumn>
Note the correct code sets DataField instead of Name. This should take care of it. The rest of your code looks fine. Thanks!
|
|
Rank: Member Groups: Member
Joined: 7/13/2011 Posts: 13
|
Thanks, that solved the problem - I can (finally) see some data
:d/
You may wish to add an example showing how to populate a grid for non database sources - this took much longer than populating a simple standard grid - and (as hoped for) a quite simple change fixed the problem
Brian
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Thanks for the suggestion. Glad that it works for you. We will add support to automatically look for this[string] on the object so that you will no longer need to explicitly implement IDataRecord in future versions.
|
|