Connect page directly to database convert static page to dynamic page.

I have page connected to static data on C# page and I want to connect that to database so that it can pick data directly from database. Till now it is extracting data from C# page.
here is my code

C# code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Practice : System.Web.UI.Page
{
clsDataAccess obj = new clsDataAccess();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetInitialRow();
//Gridview1.DataBind();
}
}

protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var ddl = (DropDownList)e.Row.FindControl("ddl");
ddl.DataSource = Book();
ddl.DataTextField = "Book_id";
ddl.DataValueField = "Book_Id";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("Select", "0"));
}
//using (SqlConnection con = new SqlConnection(@"Data Source=192.168.0.1;Initial Catalog=Stock;User Id=sa;password=123"))
//{
// con.Open();
// var ddl = (DropDownList)e.Row.FindControl("ddl");
// SqlCommand cmd = new SqlCommand("Select book_id from book", con);

// SqlDataAdapter da = new SqlDataAdapter(cmd);
// DataSet ds = new DataSet();
// da.Fill(ds);
// con.Close();
// ddl.DataSource = ds;
// ddl.DataTextField = "Book_id";
// ddl.DataValueField = "Book_Id";
// ddl.DataBind();
// ddl.Items.Insert(0, new ListItem("Select", "0"));
//}
}

protected void ButtonAdd_Click(object sender, EventArgs e)
{
AddNewBlankRow();
}

private DataTable Book()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] {
new DataColumn("Book_id", typeof(int)),
new DataColumn("Book_name", typeof(string)),
new DataColumn("Book_Price", typeof(int)) });
dt.Rows.Add(1, "C#", 120);
dt.Rows.Add(2, "ASP.Net", 450);
dt.Rows.Add(3, "MVC", 300);
dt.Rows.Add(4, "SQL", 1000);

return dt;
}

private void SetInitialRow()
{
//obj.CreateConnectionsql();
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("ddl", typeof(string)));
dt.Columns.Add(new DataColumn("Book_id", typeof(string)));
dt.Columns.Add(new DataColumn("Book_name", typeof(string)));
dt.Columns.Add(new DataColumn("Book_price", typeof(string)));
dr = dt.NewRow();
dr["ddl"] = string.Empty;
dr["Book_id"] = string.Empty;
dr["Book_name"] = string.Empty;
dr["Book_price"] = string.Empty;
dt.Rows.Add(dr);
//dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState["CurrentTable"] = dt;
Gridview1.DataSource = dt;
Gridview1.DataBind();
}

private void AddNewBlankRow()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dt.Rows.Count > 0)
{
for (int i = 1; i <= dt.Rows.Count; i++)
{
DropDownList ddl = (DropDownList)Gridview1.Rows[rowIndex].Cells[0].FindControl("ddl");
TextBox txtbookid = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txtbookid");
TextBox txtbookname = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("txtbookname");
TextBox txtbookprice = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("txtbookprice");
drCurrentRow = dt.NewRow();

dt.Rows[i - 1]["ddl"] = ddl.Text;
dt.Rows[i - 1]["book_id"] = txtbookid.Text;
dt.Rows[i - 1]["book_name"] = txtbookname.Text;
dt.Rows[i - 1]["book_price"] = txtbookprice.Text;
rowIndex++;
}
dt.Rows.Add(drCurrentRow);
ViewState["CurrentTable"] = dt;
Gridview1.DataSource = dt;
Gridview1.DataBind();
}
}
else
{
Response.Write("ViewState Value is Null");
}
SetPreviousData();
}

private void SetPreviousData()
{
//obj.CreateConnectionsql();
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DropDownList ddl = (DropDownList)Gridview1.Rows[rowIndex].Cells[0].FindControl("ddl");
TextBox txtbookid = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txtbookid");
TextBox txtbookname = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("txtbookname");
TextBox txtbookprice = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("txtbookprice");
ddl.SelectedValue = dt.Rows[i]["ddl"].ToString();
txtbookid.Text = dt.Rows[i]["book_id"].ToString();
txtbookname.Text = dt.Rows[i]["book_name"].ToString();
txtbookprice.Text = dt.Rows[i]["book_price"].ToString();
rowIndex++;
}
}
}
}

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
//obj.CreateConnectionsql();
DropDownList ddl = sender as DropDownList;
GridViewRow row = ddl.NamingContainer as GridViewRow;

DataTable dt;
if (ddl.SelectedValue == "")
{
string str = "select book_id,Book_name,Book_Price from Book";
dt = Book();
//Gridview1.DataSource = dt;
//Gridview1.DataBind();
}
else
{
string str = "select book_id,Book_name,Book_Price from Book where Book_id='" + ddl.SelectedValue + "'";
DataRow[] rows = Book().Select("Book_id=" + ddl.SelectedValue);
dt = Book().Clone();
foreach (DataRow dr in rows)
{
dt.ImportRow(dr);
}
//Gridview1.DataSource = dt;
//Gridview1.DataBind();
}
(row.Cells[1].FindControl("txtbookid") as TextBox).Text = dt.Rows[0]["book_id"].ToString();
(row.Cells[2].FindControl("txtbookname") as TextBox).Text = dt.Rows[0]["Book_name"].ToString();
(row.Cells[3].FindControl("txtbookprice") as TextBox).Text = dt.Rows[0]["Book_Price"].ToString();
}
}



Html code:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Practice.aspx.cs" Inherits="Practice" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="maincontent" Runat="Server">


<asp:GridView ID="Gridview1" runat="server" OnRowDataBound="Gridview1_RowDataBound" ShowFooter="true" AutoGenerateColumns="false">

<Columns >


<asp:TemplateField HeaderText="Select Id" >

<ItemTemplate >

<asp:DropDownList ID="ddl" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true" runat="server"></asp:DropDownList>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Book Id">

<ItemTemplate>

<asp:TextBox ID="txtbookid" Text='<%# Bind("Book_id") %>' runat="server"></asp:TextBox>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Book Name">

<ItemTemplate>

<asp:TextBox ID="txtbookname" Text='<%# Bind("Book_name") %>' runat="server"></asp:TextBox>

</ItemTemplate>


</asp:TemplateField>

<asp:TemplateField HeaderText="Book Price">

<ItemTemplate>

<asp:TextBox ID="txtbookprice" Text='<%# Bind("Book_price") %>' runat="server"></asp:TextBox>

</ItemTemplate>

<FooterStyle HorizontalAlign="Right" />

<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="ButtonAdd_Click" />
</FooterTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>

</asp:Content>