Click here to Skip to main content
12,948,130 members (67,844 online)
Rate this:
 
Please Sign up or sign in to vote.
sir m trying to bind data and image from database table to listview control but getting error i have used a handler class also to retirve image but not able to bind my data pls help....thanks in advance..

getting this error..
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'P_ID'.


Databse Design:
create Table tbl_post_property_sale
(
	P_ID int identity(1,1)primary key,
	Property_Type varchar(50)not null,
	City_Id int references tbl_City(City_Id) not null,
	Locality_Id int references tbl_Locality(Locality_Id)not null,
	[Address] varchar(200)null,
	Pincode numeric null,
	Price varchar(20) not null,
	Bedrooms int null,
	Build_up_area varchar(20) not null,
	Key_Features varchar(200)null,
	Property_Image image not null,
	Name varchar(50)not null,
	Email varchar(50)not null,
	Mobile_No numeric not null  
)


code behind:
public partial class Search_Result : System.Web.UI.Page
{
    string str = ConfigurationManager.ConnectionStrings["strconn"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!(IsPostBack))
        {
            Bindfiles();
        }
    }
 
    private void Bindfiles()
    {
        DataTable table = new DataTable();
        SqlConnection conn = new SqlConnection(str);
        string sql = "Select Property_Type,City_Id,Locality_Id,Price,Build_up_area,Bedrooms,Property_Image From tbl_post_property_sale Order By P_ID asc";
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(table);
        listview1.DataSource = table;
        listview1.DataBind();
    }
 
}



Handler code:
<%@ WebHandler Language="C#" Class="ShowImage" %>
 
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
 
public class ShowImage : IHttpHandler {
 
    public void ProcessRequest(HttpContext context)
    {
        if (context.Request.QueryString["P_ID"] == null) return;
        string str = ConfigurationManager.ConnectionStrings["strconn"].ToString();
        string property_ID = context.Request.QueryString["P_ID"];
        SqlConnection con = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand("Select Property_Type,City_Id,Locality_Id,Price,Build_up_area,Bedrooms,Property_Image From tbl_post_property_sale where P_ID = @Porperty_Id", con);
        cmd.Parameters.Add(new SqlParameter("@Porperty_Id", property_ID));
        con.Open();
 
        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        dr.Read();
        context.Response.BinaryWrite((Byte[])dr[dr.GetOrdinal("Property_Image")]);
        dr.Close();
    }
 
    
    public bool IsReusable {
        get {
            return false;
        }
    }
 
}


Form with listview:
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ListView ID="listview1" runat="server">
        <ItemTemplate>
            <table cellspacing="4" class="style1">
                <tr>
                    <td class="style2">
                        <asp:Label ID="lblpropid" runat="server">
                        <%#Eval("P_ID")%>
                        </asp:Label>
                    </td>
                    <td rowspan="8">
                        <asp:Image ID="Image1" ImageUrl='<%# "~/Handlers/ImageHandler.ashx?Property_Id="+Eval("P_ID")%>'
                                                                    BorderWidth="2px" Height="80px" Width="80px" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lblproptype" runat="server">
                        <%#Eval("Property_Type") %>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lblcity" runat="server">
                        <%#Eval("City_Id")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lbllocality" runat="server">
                        <%#Eval("Locality_Id")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lblprice" runat="server">
                        <%#Eval("Price")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                   <td class="style2">
                        <asp:Label ID="lblarea" runat="server">
                        <%#Eval("Build_up_area")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                   <td class="style2">
                        <asp:Label ID="lblbedrooms" runat="server">
                        <%#Eval("Bedrooms")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Button class="btn" ID="btnviewdetails" runat="server" Text="ViewDetails" Width="79px" />
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                         
                    </td>
                </tr>
            </table>
        </ItemTemplate>
        <AlternatingItemTemplate>
           <table cellspacing="4" bgcolor="yellow" class="style1">
                <tr>
                    <td class="style2">
                        <asp:Label ID="lblpropid" runat="server">
                        <%#Eval("P_ID") %>
                        </asp:Label>
                    </td>
                    <td rowspan="8">
                        <asp:Image ID="Image1" ImageUrl='<%# "~/Handlers/ShowImage.ashx?P_ID="+Eval("P_ID")%>'
                                                                    BorderWidth="2px" Height="80px" Width="80px" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lblproptype" runat="server">
                        <%#Eval("Property_Type") %>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lblcity" runat="server">
                        <%#Eval("City_Id")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lbllocality" runat="server">
                        <%#Eval("Locality_Id")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Label ID="lblprice" runat="server">
                        <%#Eval("Price")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                   <td class="style2">
                        <asp:Label ID="lblarea" runat="server">
                        <%#Eval("Build_up_area")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                   <td class="style2">
                        <asp:Label ID="lblbedrooms" runat="server">
                        <%#Eval("Bedrooms")%>
                        </asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                        <asp:Button class="btn" ID="btnviewdetails" runat="server" Text="ViewDetails" Width="79px" />
                    </td>
                </tr>
                <tr>
                    <td class="style2">
                         
                    </td>
                </tr>
            </table>
        </AlternatingItemTemplate>
    </asp:ListView>
      
   </form>
</body>
Posted 30-Sep-12 1:52am
Updated 30-Sep-12 1:58am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

its all right
you are welcome
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Dear,
in your select command:
that mean this

(string sql = "Select Property_Type,City_Id,Locality_Id,Price,Build_up_area,Bedrooms,Property_Image From tbl_post_property_sale Order By P_ID asc";)

you did not select P_ID so <%#Eval("P_ID") %> doesnt get any value to be filled in

you need to replace you select command with the following

string sql = "Select P_ID, Property_Type,City_Id,Locality_Id,Price,Build_up_area,Bedrooms,Property_Image From tbl_post_property_sale Order By P_ID asc";
  Permalink  
Comments
raj rautela 30-Sep-12 9:15am
   
i did what you told but image is no there only details are there
raj rautela 30-Sep-12 9:21am
   
thank u sir got it thanks a lot...
raj rautela 30-Sep-12 11:31am
   
sir i want to display city name and locality name not city id and locality id on display page it is showing city id and locality id m filling city and locality dropdown from diff table how to join..i'hv created a relation pk and fk pls help in sql joins
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Dear,

you want to display what fields and where you want to display

for example if you want to display the city name and locality name from tbl_Locality and tbl_City tables along with the tbl_post_property_sale fields

do this select command:

Select P_ID, Property_Type,City_Name,Locality_Name,Price,Build_up_area,Bedrooms,Property_Image From tbl_post_property_sale,tbl_City,tbl_Locality where tbl_post_property_sale.City_Id=tbl_City.City_Id and tbl_post_property_sale.locaity_Id=tbl_Locality.locality_Id  Order By P_ID asc



For further explaination ask me ,,
  Permalink  
v2
Comments
raj rautela 30-Sep-12 13:10pm
   
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'City_Id'. getting this error do i have to chage code in generic file also...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Inside your listView change the following:

<%#Eval("City_Id")%>
<%#Eval("Locality_Id")%>
TO
<%#Eval("City_Name")%>
<%#Eval("Locality_Name")%>
  Permalink  
v2
Comments
raj rautela 30-Sep-12 13:44pm
   
got it sir thanks a lot......sir

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,344
CHill60 3,275
Maciej Los 2,703
Jochen Arndt 1,935
ppolymorphe 1,795


Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100