Home > DeveloperSection > Forums > How can i use SetDataBinding method in Visual Studio 2010 Ultimate????
mohan kumar

Total Post:10

Points:70
Posted on    December-21-2011 6:19 PM

 C# C# 
Ratings:


 1 Reply(s)
 2206  View(s)
Rate this:
How can i use SetDataBinding method in Visual Studio 2010 Ultimate???? Actually my code goes like this..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Common;
using System.Data.ProviderBase;
using System.Data.SqlTypes;
using System.Data.Sql;
using System.Data.SqlClient;



public partial class _Default : System.Web.UI.Page
{
    SqlConnection conn = new SqlConnection("Data Source=CTS\\MSSQLSERVER2008;uid=sa;pwd=home;Initial Catalog=Northwind");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadMyGrid();
        }
    }

    public void loadMyGrid()
    {
        conn.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select EmployeeID,FirstName +"+"' '+"+"LastName as Name,Title,Address,City,Region,Country from employees", conn);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        DataViewManager dvm = new DataViewManager(ds);
        dvm.DataViewSettings["Employees"].RowFilter = "Country='USA'";
       
       dataGrid.SetDataBinding(dvm,"Employees");
\\ This SetDataBinding( ) is not available in VS 2010
        GridView1.DataSource = ds;
        GridView1.DataBind();
        conn.Close();
    }
}

What namespace should i import in order to run this code successfully??? Help me out guys...
Thanks in advance...


Arun Singh

Total Post:68

Points:476
Posted on    December-22-2011 1:46 AM

Hi Monhan Kumar,

You can use the DataTable concept instead of  DataViewManager and DataViewSettings.

check this code,

DataTable dt = ds.Tables[0];

DataRow[] dr = dt.Select("Country='USA'");

 GridView1.DataSource = dr;

GridView1.DataBind();

It might be resolve your problem.

 

 

 


Don't want to miss updates? Please click the below button!

Follow MindStick