protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindToGridView();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindToGridView();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//string aa = GridView1.DataKeys[e.RowIndex].Value.ToString();
SqlConnection con = DB.CreateCon();
con.Open();
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
string text = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();
Response.Write("<script>alert('"+id+ text+"')</script>");
SqlCommand cmd = new SqlCommand("update orders set OrderDate='" + text + "'where OrderID='" + id + "'", con);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
BindToGridView();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.PageSize = Convert.ToInt32(DropDownList1.SelectedValue);
BindToGridView();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindToGridView();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int orderid = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = orderid.ToString();
//BindToGridView();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = GridView1.Rows[index];
TableCell productName = selectedRow.Cells[1];
switch (e.CommandName)
{
case "order":
ListBox1.Items.Add(productName.Text);
break;
case "cancelorder":
if (ListBox1.Items.Count > 0)
{
int i = 0;
while (i < ListBox1.Items.Count - 1)
{
if (ListBox1.Items[i].Text == productName.Text)
{
ListBox1.Items.Remove(ListBox1.Items[i].Text);
break;
}
else
{
i++;
}
}
}
break;
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
e.Cancel = true;
Literal txtMsg = new Literal();
txtMsg.Text = "<script>alert('数据删除取消')</script>";
Page.Controls.Add(txtMsg);
}