Question

I'm developing a SharePoint solution, In an Application Page, I want to place SPGridView and I have to bind it with SQL server data.

Is it possible and if yes, how?

Was it helpful?

Solution

Yes it is possible, here is a basic example:

protected void Page_Load(object sender, EventArgs e)
{
    const string ConnectionString = @"Persist Security Info=False; Integrated Security=SSPI; Server=hercules\sqlexpress;Connect Timeout=30;Database=TestDB;";
    SqlConnection con = new SqlConnection(ConnectionString);
    SqlCommand cmd = new SqlCommand("select * from CustomerTable", con);
    SqlDataAdapter adp = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    adp.Fill(ds);

   DataTable dt = ds.Tables[0];
    gridview1.DataSource = dt.DefaultView;
    gridview1.DataBind();
 }

from here

OTHER TIPS

yes we can bind data to spgridview same as gridview.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top