Click here to Skip to main content
15,114,081 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
help me for this i have following code and i want to display data at runtime in repeater control...
Here is code behind.
C#
public partial class RepeaterDemo : System.Web.UI.Page
    {
        //string con = ConfigurationManager.ConnectionStrings["connStr"].ToString();
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ToString());
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("Select Countryid,CountryName,CountryCode,Status from Country", conn);
            
            DataSet ds = new DataSet();

            SqlDataAdapter da = new SqlDataAdapter();
            
            da.Fill(ds);
            rpt.DataSource = ds;
            rpt.DataBind();
        }
    }

here is designer code
XML
<asp:Repeater ID="rpt" runat="server">
            <HeaderTemplate>
                Country Table Data<br />
                <br />
            </HeaderTemplate>
            <ItemTemplate>
                <table border="2px"><tr><td>
                Country ID:</td><td width="50%">
                <%#Eval("Countryid") %></td></tr>
                <tr ><td>
                Country Name :</td><td width="50%">
                <%#Eval("CountryName") %></td></tr>
                <tr ><td width="50%">
                Country Code :</td><td>
                <%#Eval("CountryCode") %></td></tr>
                <tr ><td width="50%">
                Status :</td><td>
                <%#Eval("Status") %></td>
                </tr></table>
            </ItemTemplate>
            
            <FooterTemplate>Showing Country Table Data.</FooterTemplate>
            <SeparatorTemplate>

            </SeparatorTemplate>
        </asp:Repeater>

how can i bind data at page load event??

Thanks in advance.
Posted
Updated 8-Aug-12 0:19am
v2

Check this Link 1 and Link 2 it will be useful for you...
   
Comments
Ritesh Rana 8-Aug-12 5:46am
   
great...thanks
   
If you find as useful..choose this as answer...
hiii,
this is sample code

XML
Add a Repeater on the design page:

<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table cellpadding="5" cellspacing="2" >
<tr bgcolor=Gray>
<td><b>Name</b></td>
<td><b>Country</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"Name") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"Country") %></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#ccccff">
<td><%# DataBinder.Eval(Container.DataItem,"Name") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"Country") %></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

On code page write the following code on page Load:-

DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Employee");
dt.Columns.Add("Name", Type.GetType("System.String"));
dt.Columns.Add("Country", Type.GetType("System.String"));
DataRow dr = dt.NewRow();
dr[0] = "amit";
dr[1] = "India";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "rajinder";
dr[1] = "SriLanka";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "parmod";
dr[1] = "UK";
dt.Rows.Add(dr);
Repeater1.DataSource = ds;
Repeater1.DataMember = "Employee";
Repeater1.DataBind();
   
Comments
Ritesh Rana 8-Aug-12 6:27am
   
thanks..

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