ok fine.. i would just give an example of get data frm database and do databind . in C#
1. drag a GridView in the design page
2. declear the namespace in code behind page, call the Page_Load event
design page
-
-
drag a GridView
-
-
<asp:GridView ID="GridView1" runat="server">
-
</asp:GridView>
-
-
code behing page
declear namespace
-
using System;
-
using System.Data;
-
using System.Data.SqlClient;
-
using System.Configuration;
-
using System.Collections;
-
using System.Globalization;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Web.UI.HtmlControls;
-
-
-
public partial class Default2 : System.Web.UI.Page
-
{
-
SqlConnection myConnection;
-
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
// Make a connection to the database
-
myConnection = new SqlConnection("server=servername; Initial Catalog=database name; User ID=username; password=password");
-
-
// get the data frm database when page load
-
if (!IsPostBack)
-
BindGrid();
-
-
}
-
-
public void BindGrid()
-
{
-
SqlDataAdapter myCommand1 = new SqlDataAdapter("select * from tablename ", myConnection);
-
-
-
DataSet ds = new DataSet();
-
myCommand.Fill(ds, "tablename");
-
-
GridView1.DataSource = ds.Tables["tablename"].DefaultView;
-
GridView1.DataBind();
-
myCommand.Connection.Close();
-
}
-
-
-
}
-
-
-
hope that gonna help you ...