Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've created repeater for displaying some data from db table and I've used SqlDataSource for it:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
 <ItemTemplate>        
        <asp:Label ID="Label4" runat="server"><%# Eval("name")%></asp:Label><br />
 </ItemTemplate>
</asp:Repeater>

How can I do it without creating SqlDataSource? Thanks in advance.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Remove Datasourceid from Repeater and Populate it through code.

DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection("Data Source=MCDU-PC34\\SQLEXPRESS;Initial Catalog=ncpsdbb;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Student",conn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.Visible = true;
conn.Close();
share|improve this answer
    
yeah, thank you! There also must be Repeater1.DataBind(); –  User Jul 14 '13 at 11:47
    
yes, sorry missed out. –  Raghubar Jul 14 '13 at 12:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.