当前位置: 首页>>代码示例>>C#>>正文


C# DataView类代码示例

本文整理汇总了C#中DataView的典型用法代码示例。如果您正苦于以下问题:C# DataView类的具体用法?C# DataView怎么用?C# DataView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DataView类属于命名空间,在下文中一共展示了DataView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Page_Load

	protected void Page_Load(object sender, System.EventArgs e)
	{
		// Create the Connection, DataAdapter, and DataSet.
		string connectionString = "Data Source=localhost;Initial Catalog=Northwind;" +
			"Integrated Security=SSPI";
		SqlConnection con = new SqlConnection(connectionString);
		string sql = "SELECT ProductID, ProductName, UnitsInStock, UnitsOnOrder, Discontinued FROM Products";

		SqlDataAdapter da = new SqlDataAdapter(sql, con);
		DataSet ds = new DataSet();

		// Fill the DataSet
		da.Fill(ds, "Products");

		// Filter for the Chocolade product.
		DataView view1 = new DataView(ds.Tables["Products"]);
		view1.RowFilter = "ProductName = 'Chocolade'";
		Datagrid1.DataSource = view1;

		// Filter for products that aren't on order or in stock.
		DataView view2 = new DataView(ds.Tables["Products"]);
		view2.RowFilter = "UnitsInStock = 0 AND UnitsOnOrder = 0";
		Datagrid2.DataSource = view2;

		// Filter for products starting with the letter P.
		DataView view3 = new DataView(ds.Tables["Products"]);
		view3.RowFilter = "ProductName LIKE 'P%'";
		Datagrid3.DataSource = view3;

		// Bind all the data-bound controls on the page.
		// Alternatively, you could call the DataBind() method
		// of each grid separately
		this.DataBind();

	}
开发者ID:Helen1987,项目名称:edu,代码行数:35,代码来源:DataViewFilter.aspx.cs

示例2: btnAddUser_Click

    protected void btnAddUser_Click(object sender, EventArgs e)
    {
        DealerUsers objUsers = new DealerUsers();

        DataTable dtUsers = new DataTable();

        dtUsers = (DataTable)Session["DealerUsers"];

        DataView dv = new DataView();

        DataTable dt = new DataTable();

        dv = dtUsers.DefaultView;

        dv.RowFilter = "UserID='" + txtUserID.Text + "'";

        dt = dv.ToTable();

        if (dt.Rows.Count == 0)
        {
            objUsers.AddDealerUsers(Session[Constants.DealerCode].ToString(), "0", txtName.Text, txtUserID.Text, txtPassword.Text, txtUserName.Text, txtPhoneNumber.Text, Convert.ToInt32(ddlActive.SelectedItem.Value));

            FillUsers();
        }
        else
        {
            MpeAlert.Show();
            lblErrorMSg.Visible = true;
            lblErrorMSg.Text = "User ID already exists.";

        }
    }
开发者ID:BInny1,项目名称:United-Car-Exchange,代码行数:32,代码来源:ManageAccount.aspx.cs

示例3: GetClassValue

    public static string[] GetClassValue(int classId)
    {
        EasyDataProvide ModuleClass = new EasyDataProvide("ModuleClass");
        DataTable dtClass = ModuleClass.GetAllData();
        string[] classValues = new string[3];

        DataView dv3 = new DataView(dtClass);
        dv3.RowFilter = "id=" + classId;

        if (dv3.Count > 0)
        {
            classValues[2] = dv3[0]["id"].ToString();
            DataView dv2 = new DataView(dtClass);
            dv2.RowFilter = "id=" + dv3[0]["parentID"].ToString();
            if (dv2.Count > 0)
            {
                classValues[1] = dv2[0]["id"].ToString();
                DataView dv1 = new DataView(dtClass);
                dv1.RowFilter = "id=" + dv2[0]["parentID"].ToString();
                if (dv1.Count > 0)
                {

                    classValues[0] = dv1[0]["id"].ToString();
                }
            }

        }

        return classValues;
    }
开发者ID:Letractively,项目名称:dilas,代码行数:30,代码来源:ModuleClassData.cs

示例4: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        TopRecipeID = new RecipeDB().getTopRecipe();
        if (TopRecipeID != 0)
        {
            TopRecipeDiv.Visible = true;
            RecipeClass TopRecipeClass = new RecipeDB().GetRecipe(TopRecipeID);
            TopRecipeName = TopRecipeClass.RecipeName;
            TopRecipeImage = TopRecipeClass.ImagePath;
        }
        else
            TopRecipeDiv.Visible = false;

        DataTable AllRecipesTable = (new RecipeDB()).GetLatestRecipes();

        if (AllRecipesTable.Rows.Count > 0)
        {
            DataView ListView = new DataView();
            ListView.Table = AllRecipesTable;
            AllRecipeList.DataSource = ListView;
        }

        DataTable LatestArticles = new ArticleDB().GetLatestArticles();
        ArticlesRepeater.DataSource = LatestArticles;

        this.DataBind();
    }
开发者ID:karandevgan,项目名称:MyRecipes,代码行数:27,代码来源:Default.aspx.cs

示例5: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        user = User.Identity.Name;
        DataTable MyQuestionsTable = new QuesDB().GetMyQuestions(user);

        if (MyQuestionsTable.Rows.Count != 0)
        {
            DataView MyQuestions = new DataView();
            MyQuestions.Table = MyQuestionsTable;

            MyQuestionsView.SetActiveView(QuestionsPresent);
            if (SelectionCriteria.SelectedItem.Value == "All")
                MyQuestions.Sort = "PostedTime DESC";
            else if (SelectionCriteria.SelectedItem.Value == "Answered")
            {
                MyQuestions.RowFilter = "Answered = 1";
                MyQuestions.Sort = "PostedTime DESC";
            }
            else if (SelectionCriteria.SelectedItem.Value == "Unanswered")
            {
                MyQuestions.RowFilter = "Answered = 0";
                MyQuestions.Sort = "PostedTime DESC";
            }

            questionsList.DataSource = MyQuestions;
        }
        else
            MyQuestionsView.SetActiveView(NoQuestions);
    }
开发者ID:karandevgan,项目名称:MyRecipes,代码行数:29,代码来源:myquestions.aspx.cs

示例6: AddNewTest

        public void AddNewTest()
        {
            DataView dv = new DataView(_dt);
            IBindingList ib = dv;
            ib.ListChanged += new ListChangedEventHandler(OnListChanged);

            try
            {
                _args = null;
                object o = ib.AddNew();
                Assert.Equal(typeof(DataRowView), o.GetType());
                Assert.Equal(ListChangedType.ItemAdded, _args.ListChangedType);
                Assert.Equal(4, _args.NewIndex);
                Assert.Equal(-1, _args.OldIndex);

                DataRowView r = (DataRowView)o;
                Assert.Equal(25, r["id"]);
                Assert.Equal(DBNull.Value, r["name"]);
                Assert.Equal(5, dv.Count);

                _args = null;
                r.CancelEdit();
                Assert.Equal(ListChangedType.ItemDeleted, _args.ListChangedType);
                Assert.Equal(4, _args.NewIndex);
                Assert.Equal(-1, _args.OldIndex);
                Assert.Equal(4, dv.Count);
            }
            finally
            {
                ib.ListChanged -= new ListChangedEventHandler(OnListChanged);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:32,代码来源:DataViewTest_IBindingList.cs

示例7: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable articlesTable = new ArticleDB().GetAllVerifiedArticles();

        if (articlesTable.Rows.Count > 0)
        {
            DataView articlesView = new DataView();
            articlesView.Table = articlesTable;

            if (Sort.SelectedItem.Value == "Latest")
                articlesView.Sort = "PostedTime DESC";
            else if (Sort.SelectedItem.Value == "Popular")
                articlesView.Sort = "ArticleViews DESC";

            if (articlesView.Count == 0)
                PagerDiv.Visible = false;
            else
                PagerDiv.Visible = true;

            articlesList.DataSource = articlesView;

            NoArticleLbl.Visible = false;
            ArticlesDiv.Visible = true;
        }
        else
        {
            ArticlesDiv.Visible = false;
            NoArticleLbl.Visible = true;
        }
    }
开发者ID:karandevgan,项目名称:MyRecipes,代码行数:30,代码来源:articles.aspx.cs

示例8: GetVenueEvents

    protected DataView GetVenueEvents()
    {
        HttpCookie cookie = Request.Cookies["BrowserDate"];
        if (cookie == null)
        {
            cookie = new HttpCookie("BrowserDate");
            cookie.Value = DateTime.Now.ToString();
            cookie.Expires = DateTime.Now.AddDays(22);
            Response.Cookies.Add(cookie);
        }
        Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));
        string id = Request.QueryString["ID"].ToString();

        DataView dvNormal = dat.GetDataDV("SELECT EO.DateTimeStart AS Start, EO.DateTimeEnd AS " +
            "[End], E.Header, CONVERT(NVARCHAR,E.ID)+';E;'+CONVERT(NVARCHAR,EO.ID) AS ID, V.Name "+
            "FROM Event_Occurance EO, Events E, Venues " +
            "V WHERE EO.EventID=E.ID AND E.Venue=V.ID AND V.ID=" + id);

        DataView dvGroupPublic = dat.GetDataDV("SELECT EO.DateTimeStart AS Start, EO.DateTimeEnd AS " +
            "[End], E.Name AS Header, CONVERT(NVARCHAR,E.ID)+';G;'+CONVERT(NVARCHAR,EO.ID) AS ID, EO.ID "+
            "AS ReoccurrID, V.Name FROM GroupEvent_Occurance EO, GroupEvents E, Venues " +
            "V WHERE E.EventType='1' AND EO.GroupEventID=E.ID AND EO.VenueID=V.ID AND V.ID=" + id);

        DataView dvGroupInvited = new DataView();
        if (Session["User"] != null)
        {
            dvGroupInvited = dat.GetDataDV("SELECT EO.DateTimeStart AS Start, EO.DateTimeEnd AS " +
            "[End], E.Name AS Header,  CONVERT(NVARCHAR,E.ID)+';G;'+CONVERT(NVARCHAR,EO.ID) AS ID, EO.ID " +
            "AS ReoccurrID, V.Name FROM GroupEvent_Occurance EO, GroupEvents E, GroupEvent_Members GEM, Venues " +
            "V WHERE E.EventType <> '1' AND GEM.UserID=" + Session["User"].ToString() + " AND GEM.GroupEventID=E.ID AND GEM.ReoccurrID=EO.ID " +
            "AND EO.GroupEventID=E.ID AND EO.VenueID=V.ID AND V.ID=" + id);
        }

        return MergeDV(MergeDV(dvGroupPublic, dvGroupInvited), dvNormal);
    }
开发者ID:aleksczajka,项目名称:Hippo-Code---OLD,代码行数:35,代码来源:VenueCalendar.aspx.cs

示例9: dpNextPrevious_PagePropertiesChanging

    protected void dpNextPrevious_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    {
        int startRow = e.StartRowIndex;

        if (this.Run)
        {
            // Reset the start row so all rows are returned.  This is needed when the user
            // clicks on view all records.
            startRow = 0;
        }
        // Re-bind
        dpNextPrevious1.SetPageProperties(startRow, e.MaximumRows, false);
        dpNextPrevious2.SetPageProperties(startRow, e.MaximumRows, false);

        con = new SqlConnection(ConfigurationManager.ConnectionStrings[dbConnStr].ConnectionString);
        con.Open();

        dataView = new DataView();

        dataView = reportTable.DefaultView;
        dataView.Sort = string.Format("{0} {1}", sortExpression, sortOrder);

        con.Close();

        lvAccessories.DataSource = dataView;
        lvAccessories.DataBind();

        ViewState["dataTable"] = reportTable;
    }
开发者ID:Wynnah,项目名称:ASP.NET,代码行数:29,代码来源:Accessories.aspx.cs

示例10: DataViewTest

        public DataViewTest()
        {
            _dataTable = new DataTable("itemTable");
            _dc1 = new DataColumn("itemId");
            _dc2 = new DataColumn("itemName");
            _dc3 = new DataColumn("itemPrice");
            _dc4 = new DataColumn("itemCategory");

            _dataTable.Columns.Add(_dc1);
            _dataTable.Columns.Add(_dc2);
            _dataTable.Columns.Add(_dc3);
            _dataTable.Columns.Add(_dc4);
            DataRow dr;
            _seed = 123;
            _rowCount = 5;
            _rndm = new Random(_seed);
            for (int i = 1; i <= _rowCount; i++)
            {
                dr = _dataTable.NewRow();
                dr["itemId"] = "item " + i;
                dr["itemName"] = "name " + _rndm.Next();
                dr["itemPrice"] = "Rs. " + (_rndm.Next() % 1000);
                dr["itemCategory"] = "Cat " + ((_rndm.Next() % 10) + 1);
                _dataTable.Rows.Add(dr);
            }
            _dataTable.AcceptChanges();
            _dataView = new DataView(_dataTable);
            _dataView.ListChanged += new ListChangedEventHandler(OnListChanged);
            _listChangedArgs = null;
        }
开发者ID:ericeil,项目名称:corefx,代码行数:30,代码来源:DataViewTest.cs

示例11: decryptDataView

  public DataView decryptDataView(DataView dataView) {
    //  Converting DataView into DataTable
    DataTable EncryptedTable = dataView.ToTable();
    //  getting table rows count
    int tableRows = EncryptedTable.Rows.Count;
    // getting table coulumns count
    int tableColumns = EncryptedTable.Columns.Count;

    // Creating a new Table to handle Encrypted Values
    DataTable UncryptedTable = new DataTable();

    //copying each table row
    for (int i=0; tableRows < i; i++) {
      // copying each table column
      for (int j=0; tableColumns < j; i++) {
        UncryptedTable.Rows[i][j] = EncryptedTable.Rows[i][j];
        // Unincrypting data
        UncryptedTable.Rows[i][j] = Crypto.Decrypt(EncryptedTable.Rows[i][j].ToString());
      }
    }
    // Converting Uncrypted Table into a Dataview for Response
    var UncryptedDataView = new DataView(UncryptedTable);
    // Sending Uncrypted Data View
    return UncryptedDataView;
  }
开发者ID:ioEtep,项目名称:amaral-guincho-web,代码行数:25,代码来源:CryptoHandler.cs

示例12: btnSortByName_Click

    protected void btnSortByName_Click(object sender, EventArgs e)
    {
        dv = (DataView)GridView1.DataSource;

        if (listTeam.SelectedItem.ToString() == "" || listPosition.SelectedItem.ToString() == "")
        {

            dv.Sort = "sukunimi ASC";
            GridView1.DataSource = dv;
            GridView1.DataBind();

        }
        else
        {
            if (listPosition.SelectedItem.ToString() != "")
            {
                dv.RowFilter = "seura = " + "'" + listTeam.SelectedItem.ToString() + "' AND pelipaikka = " + "'" + listPosition.SelectedItem.ToString() + "'";
            }
            else
            {
                dv.RowFilter = "seura = " + "'" + listTeam.SelectedItem.ToString() + "'";
                Label1.Text = "seura = " + "'" + listTeam.SelectedItem.ToString() + "'";

            }

            dv.RowStateFilter = DataViewRowState.CurrentRows;
            dv.Sort = "sukunimi ASC";
            GridView1.DataSource = dv;
            GridView1.DataBind();
        }
    }
开发者ID:joelkarttunen,项目名称:viikkotehtava-1,代码行数:31,代码来源:f6761_SmLiigaOudotOliot.aspx.cs

示例13: initDateDataView

    private void initDateDataView()
    {
        if (!"".Equals(ddlDate.Text))
        {
            DataView dvStock = new DataView();
            //if (ddlDate.SelectedIndex.Equals(0))
            //{
            //    dvStock = FundDataMem.GetData(FundDataSetType.FundDataType.基金持股历史, "FUNDID:" + HidFundID.Value + ";SEASON:" + ddlDate.Text);
            //}
            //else
            //{

            //}
            dvStock = FundDataMem.GetData(FundDataSetType.FundDataType.基金持股历史, HidFundID.Value.Trim(), ddlDate.Text.Trim());

            //基金持股详情
            if (dvStock != null && dvStock.Table.Rows.Count > 0)
            {
                GridViewStock.DataSource = dvStock;
                GridViewStock.DataBind();
            }

            else
            {
                tDate.Visible = false;
                Label1.Visible = true;
            }
            //填写序号列
            for (int i = 0; i < GridViewStock.Rows.Count; i++)
                GridViewStock.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
        }
    }
开发者ID:PhilTheAir,项目名称:Aspnet,代码行数:32,代码来源:FundHoldStock.aspx.cs

示例14: btnGetIncidents_Click

    protected void btnGetIncidents_Click(object sender, EventArgs e)
    {
        lstIncidents.Items.Clear();
        myView = (DataView)dsIncidents.Select(DataSourceSelectArguments.Empty);
        myView.RowFilter = "CustomerID='" + txtCustomerID.Text + "' AND  DateClosed IS NOT NULL";

        lstIncidents.Items.Add("--Select an incident--");
        lstIncidents.Items[0].Value = "None";

        if (myView.Count == 0)
        {
            Deny();
            lstIncidents.Items.Clear();
            lstIncidents.Items.Add("There are no incidents linked to this account");
        }

        else
        {
            custid = Convert.ToInt32(txtCustomerID.Text);
            int i = 1;
            foreach (DataRowView v in myView)
            {
                DataRowView rowResult = v;
                inc = new Incident(rowResult);
                lstIncidents.Items.Add(inc.CustomerIncidentDisplay());
                lstIncidents.Items[i].Value = Convert.ToString(inc.IncidentID);
                i++;
            }
            lstIncidents.Focus();
            Allow();
        }
    }
开发者ID:KSEkstrand,项目名称:Case4,代码行数:32,代码来源:CustomerSurvey.aspx.cs

示例15: GetModelsInfo

 public void GetModelsInfo()
 {
     try
     {
         //var objModel = new List<MakesInfo>();
         //objModel = Session["AllModel"] as List<MakesInfo>;
         DataSet dsModels = Session[Constants.AllModel] as DataSet;
         int makeid = Convert.ToInt32(ddlMake.SelectedItem.Value);
         DataView dvModel = new DataView();
         DataTable dtModel = new DataTable();
         dvModel = dsModels.Tables[0].DefaultView;
         dvModel.RowFilter = "MakeID='" + makeid.ToString() + "'";
         dtModel = dvModel.ToTable();
         ddlModel.DataSource = dtModel;
         ddlModel.Items.Clear();
         ddlModel.DataTextField = "Model";
         ddlModel.DataValueField = "MakeModelID";
         ddlModel.DataBind();
         ddlModel.Items.Insert(0, new ListItem("Unspecified", "0"));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
开发者ID:hugo-mirad,项目名称:newcarsale,代码行数:25,代码来源:QCDataView.aspx.cs


注:本文中的DataView类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。