A field or property with the name Empid was not found on the selected data source

Last Reply on Apr 10, 2012 10:38 PM By Mudassar

Posted on Apr 09, 2012 09:57 AM

Hi,

I am using two gridviews with one datasourse. 

I am getting one error 

A field or property with the name 'Empid' was not found on the selected data source.

Description: 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.

Exception Details: System.Web.HttpException: A field or property with the name '
Empid' was not found on the selected data source.

Source Error: 

 Can you please help me to resolve above error ? 

My code is 

  

    <asp:GridView	id="gridview"
	runat="server" DataSourceID = "SqlDataSource1"
	        PageSize="30"  EmptyDataText = "No Records Found" EmptyDataRowStyle-HorizontalAlign ="Center"
               AllowPaging="true"    
    HorizontalAlign="Center" BorderColor ="Black"   Width = "762" Font-Names="Calibri"
  AllowSorting = "true"  Visible= "false" AutoGenerateColumns= "false" >
               
              
  <Columns>        
  
    
                 <asp:BoundField DataField="EmpID" HeaderText="Emp ID" SortExpression = "Empid" />  
                 <asp:BoundField DataField="Emp Name" HeaderText="Emp Name"  SortExpression = "Emp Name"/>  
                 <asp:BoundField DataField="Salary" HeaderText="Salary" SortExpression = "Salary"/>          
                
                         
                <asp:TemplateField  HeaderText ="Approved Salary Received"  >
                    <ItemTemplate >
                        <asp:CheckBox ID="chkStatus" runat="server"/>
                    </ItemTemplate>                    
                </asp:TemplateField>
             
            
            </Columns>
         <HeaderStyle BackColor="SteelBlue" Font-Bold="true" ForeColor="White"  Font-Size = "Medium"  Font-Names="Calibri"   Wrap ="true"   Height = "30"  CssClass="fixedAtTop" />
	         <RowStyle BackColor="AliceBlue"  Font-Size = "Small"  Font-Names="Calibri"  />
	         <AlternatingRowStyle BackColor="White"  Font-Size = "Small"  Font-Names="Calibri"/>
      


              <EmptyDataRowStyle  Font-Size = "Medium" ForeColor ="Black" Font-Bold ="true"  HorizontalAlign = "Center" BackColor = "AliceBlue"  />
                 <PagerStyle   
                BackColor="SteelBlue"   
                ForeColor="Snow"   
                Font-Size="Large"  
                Font-Names="Calibri"  
                /> 
      
                 <PagerSettings 
            Position="Bottom" 
               mode = "NumericFirstLast"  
               LastPageText = "Last Page" />
               
            
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
   ConnectionString="<%$ appSettings:connString  %>"         
   SelectCommandType ="StoredProcedure"  SelectCommand = "Empsalaryreceived" >
 
     <SelectParameters > 
    
       <asp:Parameter Name="EmpID" Type="string"  />
       <asp:Parameter Name = "Emptype" Type = "String" /> 
       <asp:Parameter Name = "Block" Type = "String" /> 

                    </SelectParameters>
   </asp:SqlDataSource>

 <asp:GridView	id="gridview1"
	runat="server" DataSourceID = "SqlDataSource1"
	        PageSize="30" EmptyDataText = "No Records Found2" EmptyDataRowStyle-HorizontalAlign ="Center"
               AllowPaging="true"    
    HorizontalAlign="Center" BorderColor ="Black"   Width = "762" Font-Names="Calibri"
  AllowSorting = "true"  Visible= "false" AutoGenerateColumns= "true"  >
                            
 

         <HeaderStyle BackColor="SteelBlue" Font-Bold="true" ForeColor="White"  Font-Size = "Medium"  Font-Names="Calibri"   Wrap ="true"   Height = "30"  CssClass="fixedAtTop" />
	         <RowStyle BackColor="AliceBlue"  Font-Size = "Small"  Font-Names="Calibri"  />
	         <AlternatingRowStyle BackColor="White"  Font-Size = "Small"  Font-Names="Calibri"/>
      
                <EmptyDataRowStyle  Font-Size = "Medium" ForeColor ="Black" Font-Bold ="true"  HorizontalAlign = "Center" BackColor = "AliceBlue"  />
                 <PagerStyle   
                BackColor="SteelBlue"   
                ForeColor="Snow"   
                Font-Size="Large"  
                Font-Names="Calibri"  
                /> 
      
                 <PagerSettings 
            Position="Bottom" 
               mode = "NumericFirstLast"  
               LastPageText = "Last Page" />
               
            
</asp:GridView>

 

You are viewing reply posted by: Mudassar on Apr 10, 2012 10:38 PM.
Posted on Apr 10, 2012 10:38 PM

Try using TemplateFields instead of BoundFields