Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
Please help me in creating a repeater control with image box on one side and a few labels for writing texts on the other.
I want the repeater to look like the one in
http://www.lovevivah.com/index.php/search_controller/process_quick_search/[^].
Thank You
Posted

1 solution

hi skand pratal singh,

Please see below code.it will solve your problem. i have implemented it:

.aspx code:

XML
<asp:Repeater ID="rpt" runat="server" OnItemDataBound="rpt_ItemDataBound">
                <ItemTemplate>
                    <table>
                        <tr>
                            <td>
                                <asp:Image ID="img" runat="server" ImageUrl='<%#"~/images/"+Eval("Image") %>' Width="160px" Height="169px"/>
                            </td>
                            <td>
                                <table>
                                    <tr>
                                        <td>
                                            Name :
                                        </td>
                                        <td>
                                            <asp:Label ID="lblname" runat="server" Text='<%#Eval("Firstname") %>'></asp:Label></td>
                                    </tr>
                                    <tr>
                                        <td>
                                            Mobile :
                                        </td>
                                        <td>
                                            <asp:Label ID="lblmobile" runat="server" Text='<%#Eval("Mobile") %>'></asp:Label></td>
                                    </tr>
                                    <tr>
                                        <td>
                                            Salary :
                                        </td>
                                        <td>
                                            <asp:Label ID="lblsalary" runat="server" Text='<%#Eval("Salary") %>'></asp:Label></td>
                                    </tr>
                                    <tr>
                                        <td>
                                            Sex :
                                        </td>
                                        <td>
                                            <asp:Label ID="lblsex" runat="server" Text='<%#Eval("Sex") %>'></asp:Label></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:Repeater>


.aspx.cs code:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default3 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Demo"]);
    protected void Page_Load(object sender, EventArgs e)
    {
        bindRepeater();
    }

    private void bindRepeater()
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from contact", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            rpt.DataSource = dt;
            rpt.DataBind();
        }
        con.Close();
    }
   
}
 
Share this answer
 
Comments
Skand Pratap Singh 6-Dec-12 1:15am    
hi kk,
i am getting the following error, please tell me how to resolve it?
Compiler Error Message: CS1061: 'ASP.repeater_aspx' does not contain a definition for 'rpt_ItemDataBound' and no extension method 'rpt_ItemDataBound' accepting a first argument of type 'ASP.repeater_aspx' could be found (are you missing a using directive or an assembly reference?)

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