HOW CAN I USE SETDATABINDING METHOD IN VISUAL STUDIO 2010 ULTIMATE????

mohan kumar

Total Post:10

Points:70
Posted by  mohan kumar
C# 
C#
 2511  View(s)
Ratings:
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...
  1. Arun Singh

    Post:68

    Points:476
    Re: How can i use SetDataBinding method in Visual Studio 2010 Ultimate????

    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.

     

     

     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!