problema listbox c#

alfinete

Power Member
Código:
  DataTable dt = null;

          Web.ENB.BussinessLayer.EnbDcNote ograde = new eb.ENB.BussinessLayer.EnbDcNote();

         
            dt= ograde.ENBDcGradeSELById(Int32.Parse(id));

            lstNotasDisp.DataMember  = dt.Rows[1].ToString() ;
            lstNotasDisp.DataValueField = dt.Rows[0].ToString() ;
            lstNotasDisp.DataSource = dt;
            lstNotasDisp.DataBind();

tenho este codigo para por dados numa listbox atraves de uma datatable

a datateble tem dados que ja veridfiquei

e dá este erro

Código:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'System.Data.DataRow'.          body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}           p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}          b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}          H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }          H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }          pre {font-family:"Lucida Console";font-size: .9em}          .marker {font-weight: bold; color: black;text-decoration: none;}          .version {color: gray;}          .error {margin-bottom: 10px;}          .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }         [B][I]DataBinding: 'System.Data.DataRowView' does not contain a property with  the name 'System.Data.DataRow'.[/I] [/B]

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif][B]Description:  [/B]An unhandled exception occurred during the execution of the current web  request. Please review the stack trace for more information about the error and  where it originated in the code. 

[B]Exception Details:  [/B]System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not  contain a property with the name 'System.Data.DataRow'.

[B]Source  Error:[/B] 

   [COLOR=Black]Line 78:             lstNotasDisp.DataValueField = dt.Rows[0].ToString() ;
Line 79:             
[/COLOR][COLOR=red]Line 80:             lstNotasDisp.DataBind();   
[/COLOR]Line 81:         }
Line 82: 
[B]Source File:  [/B]C:\alfredo\my  projects\sourcesave\enb_framework\development\project\ENBFramework\EnbAttendanceandNotes\EnbAttendanceandNoteswucontrol\wucEnbIntroductionNotesInsert.ascx.cs[B]     Line: [/B]80 [/FONT]

agradecia uma ajuda
 
Código:
            lstNotasDisp.DataMember  = dt.Rows[1].ToString() ;
            lstNotasDisp.DataValueField = dt.Rows[0].ToString() ;


penso que o erro esteja nestas duas linhas, o ToString() devolve o nome do objecto neste caso
'System.Data.DataRowView', o que tu queres é o valor de uma celula dentro da row
 
Back
Topo