How to bind GridView with DataSet in ASP.Net and c#.
In this article I am using ASP.Net GridView control to display data from database.I am using Dataset to fill data and display in Grid.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bindGridView();
}
}
public void bindGridView()
{
SqlConnection myconnection;
SqlCommand mycmd;
SqlDataAdapter myda;
DataSet ds;
myconnection = new SqlConnection("Data Source=YourServer;Initial Catalog=Test;Integrated Security=True");
myda = new SqlDataAdapter("Select * from tblCustDetail ", myconnection);
ds = new DataSet();
myda.Fill(ds);
gvCust.DataSource = ds;
gvCust.DataBind();
}
0 comments:
Post a Comment