本文整理汇总了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();
}
示例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.";
}
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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;
}
}