Bind Gridview using Datatable in Asp.Net

How to Bind Gridview using Datatable in Asp.Net ?

October 14, 2020
<asp:Repeater runat="server" ID="rptblogs">
    <ItemTemplate>
        <h1><%#Eval("Name"%></h1>
        <p><%#Eval("Description"%></p>
        <p><a href="<%#Eval("Link"%>"></a></p>
 
    </ItemTemplate>
</asp:Repeater>
using (SqlConnection con = new SqlConnection("connection_string"))
{
    using (SqlCommand cmd = new SqlCommand("select * from blogs"con))
    {
        cmd.CommandType = CommandType.Text;
        using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
        {
            using (DataTable dt = new DataTable())
            {
                sda.Fill(dt);
                rptblogs.DataSource = dt;
                rptblogs.DataBind();
            }
        }
    }
}

Post Comments(0)

Leave a reply

Will not be displayed in comment box .

Loading...