protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView1.Columns[(int)Colums.TIME_LT].Visible = true; GridView1.Columns[(int)Colums.TIME_LT_FULL].Visible = false; GridView1.Sort(Colums.TIME_LT.ToString(), SortDirection.Ascending); } Components_HeaderCell hc; if (GridView1.HeaderRow != null) { foreach (TableCell tc in GridView1.HeaderRow.Cells) { for (int i = 0; i < tc.Controls.Count; i++) { if (tc.Controls[i] is Components_HeaderCell) { hc = (Components_HeaderCell)tc.Controls[i]; hc.lbDown_Click = btnClick; hc.lbUp_Click = btnClick; } } } } }
protected void Button1_Click(object sender, EventArgs e) { string cs = WebConfigurationManager.ConnectionStrings["automationConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(cs); conn.Open(); string cmd = "INSERT INTO job(machineID,customerID,groupleaderID,worker2ID,startdate) VALUES(@mId,@cId,@gId,@wId,@sdID)"; SqlCommand command = new SqlCommand(cmd, conn); command.Parameters.AddWithValue("@mId", DropDownList1.SelectedValue); command.Parameters.AddWithValue("@cId", DropDownList2.SelectedValue); command.Parameters.AddWithValue("@gId", ddlGroupLeader.SelectedValue); command.Parameters.AddWithValue("@wId", DropDownList4.SelectedValue); command.Parameters.AddWithValue("@sdID", DateTime.ParseExact(TextBoxSD.Text, "dd-MM-yyyy", null)); //command.Parameters.AddWithValue("@cpId", DropDownList5.SelectedValue); command.ExecuteNonQuery(); conn.Close(); GridView1.Sort("machineID", SortDirection.Ascending); SqlDataSourcemachine.Update(); DataView dvj = (DataView)(sdcj.Select(DataSourceSelectArguments.Empty)); DataView dvw = (DataView)(sdcw.Select(DataSourceSelectArguments.Empty)); dvw.Sort = "workerID"; for (int i = 0; i < dvj.Table.Rows.Count; i++) { h.Value = dvj.Table.Rows[i][5].ToString(); sdcw.Update(); h.Value = dvj.Table.Rows[i][6].ToString(); sdcw.Update(); } DataView dvpcurrentjob = (DataView)(selectcurrentjob.Select(DataSourceSelectArguments.Empty)); currjob.Value = dvpcurrentjob.Table.Rows[0][0].ToString(); makeplan(dvpcurrentjob.Table.Rows[0][0].ToString(), Convert.ToDateTime(dvpcurrentjob.Table.Rows[0]["startdate"])); conn.Open(); SqlCommand cm = new SqlCommand("insert into [job-worker](job,wid,time,status) values(@j1,@w1,@t1,@s1)", conn); cm.Parameters.AddWithValue("@j1", currjob.Value); cm.Parameters.AddWithValue("@t1", DateTime.ParseExact(TextBoxSD.Text, "dd-MM-yyyy", null)); cm.Parameters.AddWithValue("@s1", "ADDED"); cm.Parameters.AddWithValue("@w1", ddlGroupLeader.SelectedValue); cm.ExecuteNonQuery(); cm = new SqlCommand("insert into [job-worker](job,wid,time,status) values(@j2,@w2,@t2,@s2)", conn); cm.Parameters.AddWithValue("@j2", currjob.Value); cm.Parameters.AddWithValue("@t2", DateTime.ParseExact(TextBoxSD.Text, "dd-MM-yyyy", null)); cm.Parameters.AddWithValue("@s2", "ADDED"); cm.Parameters.AddWithValue("@w2", DropDownList4.SelectedValue); cm.ExecuteNonQuery(); conn.Close(); Response.Redirect("job.aspx"); }
//自定义排序 protected void LinkButtonHeader_Click(object sender, EventArgs e) { LinkButton lBtn = sender as LinkButton; if (lBtn != null) { string sortExpression = lBtn.CommandArgument;//获取排序字段,进行排序 SortDirection sortDirection = GridView1.SortDirection; SortDirection newSortDirection; switch (GridView1.SortDirection) { case SortDirection.Ascending: newSortDirection = SortDirection.Descending; break; //取反 case SortDirection.Descending: newSortDirection = SortDirection.Ascending; break; //取反 default: newSortDirection = SortDirection.Ascending; break; } GridView1.Sort(sortExpression, newSortDirection); if (ViewState["lstPurchaseOrder"] != null) { GridView1.DataSource = (List <PurchaseOrder>)ViewState["lstPurchaseOrder"]; GridView1.DataBind(); //由于是绑定的数据源控件,所以需要重新进行绑定 } ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Guid.NewGuid().ToString(), "hiddenWaitDiv('divWait');", true); //js提示 } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView1.Sort("Id", SortDirection.Descending); } }
private void Default_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView1.Sort("Created", SortDirection.Descending); } }
public void btnClick(object sender, CommandEventArgs e) { string dle = e.CommandArgument.ToString(); SortDirection sd = SortDirection.Ascending; if (e.CommandName == "Down") { sd = SortDirection.Descending; } GridView1.Sort(dle, sd); GridView1.DataBind(); }
protected void Button1_Click(object sender, EventArgs e) { // GridView2.Visible = false; // GridView1.Visible = true; if (CheckBox1.Checked) { GridView1.Sort("date", SortDirection.Descending); } else { GridView1.Sort("date", SortDirection.Ascending); } }
protected void btnSubmitWORKER_Click(object sender, EventArgs e) { if (RadioButtonGroupLeader.Checked) { SqlDataSourceAddWorker.InsertParameters["groupLeader"].DefaultValue = TextBox_workername.Text; } else { SqlDataSourceAddWorker.InsertParameters["groupLeader"].DefaultValue = DropDownListLeaders.SelectedItem.Text; } SqlDataSourceAddWorker.InsertParameters["joindate"].DefaultValue = DateTime.Now.ToString(); SqlDataSourceAddWorker.Insert(); TextBox_workername.Text = ""; DropDownListLeaders.ClearSelection(); DropDownListLeaders.DataBind(); GridView1.Sort("groupLeader", SortDirection.Ascending); }
protected void Page_Load(object sender, EventArgs e) { // todo - Redirect away if not signed in if (string.IsNullOrEmpty(User.Identity.GetUserId())) { Response.StatusCode = 403; Response.Redirect("/Default"); } // Set/Overload the UserId for the Select query that will render FundingSources for User ObjectDataSource1.SelectParameters["UserId"].DefaultValue = User.Identity.GetUserId(); // Initial Sort if (!IsPostBack) { GridView1.Sort("DateCreated", SortDirection.Descending); } }
protected void Page_Load(object sender, EventArgs e) { table = GridDataSource.GetTable(); Title = table.DisplayName; GridDataSource.Include = table.ForeignKeyColumnsNames; InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert); // Disable various options if the table is readonly if (table.IsReadOnly) { GridView1.Columns[0].Visible = false; InsertHyperLink.Visible = false; } //GridDataSource.OrderBy = "InvoiceNumber"; if (!Page.IsPostBack) { GridView1.Sort("DateEntered", SortDirection.Descending); } }
//自定义排序 protected void LinkButtonHeader_Click(object sender, EventArgs e) { //LinkButton lBtn = sender as LinkButton; //if (lBtn != null) //{ // string sortExpression = "WHCode,CargoCode,"; // string sortExpressionRight = "ChangeTime,TableAccountID"; // if (sortExpression.Contains(lBtn.CommandArgument) == false && sortExpressionRight.Contains(lBtn.CommandArgument) == false) // { // sortExpression += lBtn.CommandArgument;//获取排序字段,进行排序 // } // if (GridView1.SortDirection == SortDirection.Ascending) // GridView1.Sort(sortExpression, SortDirection.Descending); // else // GridView1.Sort(sortExpression, SortDirection.Ascending); // ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Guid.NewGuid().ToString(), "hiddenWaitDiv('divWait');", true);//js提示 //} LinkButton lBtn = sender as LinkButton; if (lBtn != null) { string sortExpression = lBtn.CommandArgument;//获取排序字段,进行排序 SortDirection sortDirection = GridView1.SortDirection; SortDirection newSortDirection; switch (GridView1.SortDirection) { case SortDirection.Ascending: newSortDirection = SortDirection.Descending; break; //取反 case SortDirection.Descending: newSortDirection = SortDirection.Ascending; break; //取反 default: newSortDirection = SortDirection.Ascending; break; } GridView1.Sort(sortExpression, newSortDirection); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Guid.NewGuid().ToString(), "hiddenWaitDiv('divWait');", true);//js提示 } }
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { GridView1.Sort(DropDownList1.SelectedValue, SortDirection.Ascending); }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Commit") { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32(e.CommandArgument); //Get the new Values. GridViewRow row = GridView1.Rows[index]; String CollectionStateID = ((DropDownList)row.Cells[7].Controls[1]).SelectedValue; String CollectionID = ((Label)row.Cells[0].Controls[1]).Text; // Code to update the DataSource. //collection.sp_update_collecction_result SqlConnection sqlConnection1 = new SqlConnection(CumplimentSqlDataSource.ConnectionString); SqlCommand cmd = new SqlCommand(); try { cmd.CommandText = "collection.sp_update_collecction_result"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = sqlConnection1; cmd.Parameters.AddWithValue("@Period", ddlPeriod.SelectedValue); cmd.Parameters.AddWithValue("@CollentionID", CollectionID); cmd.Parameters.AddWithValue("@CollectionStatID ", CollectionStateID); sqlConnection1.Open(); cmd.ExecuteNonQuery(); sqlConnection1.Close(); //Reset the edit index. GridView1.EditIndex = -1; GetValues(); } catch (Exception exp) { ErrorLabel.Text = exp.Message; ErrorLabel.Visible = true; } } else if (e.CommandName == "Sort") { ////CumplimentSqlDataSource.SortParameterName if (e.CommandArgument.ToString() == "DebtAmount") { if ((SortDirection)ViewState["SortColumnDirection"] == SortDirection.Ascending) { GridView1.Sort("DebtAmount", SortDirection.Descending); ViewState["SortColumn"] = "DebtAmount"; ViewState["SortColumnDirection"] = SortDirection.Descending; } else { GridView1.Sort("DebtAmount", SortDirection.Ascending); ViewState["SortColumn"] = "DebtAmount"; ViewState["SortColumnDirection"] = SortDirection.Ascending; } } else if (e.CommandArgument.ToString() == "ReceiptNumber") { if ((SortDirection)ViewState["SortColumnDirection"] == SortDirection.Ascending) { GridView1.Sort("ReceiptNumber", SortDirection.Descending); ViewState["SortColumn"] = "ReceiptNumber"; ViewState["SortColumnDirection"] = SortDirection.Descending; } else { GridView1.Sort("ReceiptNumber", SortDirection.Ascending); ViewState["SortColumn"] = "ReceiptNumber"; ViewState["SortColumnDirection"] = SortDirection.Ascending; } } else if (e.CommandArgument.ToString() == "PolicyNumber") { if ((SortDirection)ViewState["SortColumnDirection"] == SortDirection.Ascending) { GridView1.Sort("PolicyNumber", SortDirection.Descending); ViewState["SortColumn"] = "PolicyNumber"; ViewState["SortColumnDirection"] = SortDirection.Descending; } else { GridView1.Sort("PolicyNumber", SortDirection.Ascending); ViewState["SortColumn"] = "PolicyNumber"; ViewState["SortColumnDirection"] = SortDirection.Ascending; } } } }