Question

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.

Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top