Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used a databinder in grid view in asp.net.. In addition to it, i have used search box that search for a record from grid(grdOffice).. the databinder works fine when user views the grid view.. but as user search the content in the grid view, an error rises ...

the databinder tag is:

<asp:Label ID="lblProfile" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.genderName") %>'>


c# code for data bound when user enters a text and click on search is..

C#
grdOffice.DataSourceID = string.Empty;
       grdOffice.DataSource = searchOfficeName;
       grdOffice.DataBind();


the error i get is: "DataBinding: '.DAL.Profile' does not contain a property with the name 'gender'."

I have gender id attribute in table Profile and i pertain to bring genderName (that contains male and female) of gender table in grid view of Profile table based upon gender id.

When I am binding grdOffice,, i cannot bind in DataBinder.Eval

Any help??
Posted
Updated 3-Oct-13 19:13pm
v3
Comments
Kamran Ajmal 3-Oct-13 7:47am    
You can not call the GenderName directly as you are binding with table that contains only genderID not gender Name, Which data type you are using to bind the Grid, I mean, Entity Frame work, Linq, Store Procudure ?
Codes DeCodes 4-Oct-13 0:24am    
kamran i am using linq..

The error clearly shows that you have no gender name property bound . Check whether your DAL fetches you the GenderName property too
 
Share this answer
 
Comments
Codes DeCodes 4-Oct-13 0:23am    
I have already done that.. DAL fetches gendername property. as mentioned in question the grid works well before search is done means DAL is fetching gendername property..
please check that in your DataSource genderNams available or not. If not then you can't use this for databinding in gridview. further if you want to display genderName on behalf of gender id then i have a solution for you which you can use easily as :
<asp:label Id="lblProfile" runat="server" Text='<%#(Convert.ToString(Eval("genderId"))==1?Male:Female) %>'>

means if genderId is 1 then lable lblProfile shows Male else Female
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900