关于GridView1中编辑刷新问题,求指点
前台:<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="UI.aspx.cs" Inherits="异动处理.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server" >
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="border:auto" >
<div style="background-color: #008080; width: 1224px;"> <asp:Label ID="Label3"
runat="server" Text="考勤系统异动处理:" ></asp:Label>
<asp:Label ID="Label4" runat="server" Text="选择:"></asp:Label>
<asp:DropDownList ID="DropDownList3" runat="server" Height="26px"
onselectedindexchanged="DropDownList3_SelectedIndexChanged" Width="74px">
<asp:ListItem>管理员</asp:ListItem>
<asp:ListItem>教师</asp:ListItem>
<asp:ListItem>学生</asp:ListItem>
</asp:DropDownList>
</div>
<div style="background-color: #008080; width: 1224px;">
<asp:Label ID="Label1" runat="server" Text="查询范围:"></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem>--请选择--</asp:ListItem>
<asp:ListItem>教工号查询</asp:ListItem>
<asp:ListItem>姓名查询</asp:ListItem>
<asp:ListItem>周次查询</asp:ListItem>
<asp:ListItem>节次查询</asp:ListItem>
<asp:ListItem>课程查询</asp:ListItem>
<asp:ListItem>考勤情况查询</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>--请选择--</asp:ListItem>
<asp:ListItem>第一周</asp:ListItem>
<asp:ListItem>第二周</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="确定" onclick="Button1_Click"
Width="79px" Height="25px" />
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="请输入:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<div style="background-color: #008080; height: 402px; width: 1224px;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Height="230px" Width="710px" onrowediting="GridView1_RowEditing"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowupdating="GridView1_RowUpdating" >
<Columns>
<asp:BoundField DataField="教工号" HeaderText="教工号" />
<asp:BoundField DataField="姓名" HeaderText="姓名" />
<asp:BoundField DataField="周次" HeaderText="周次" />
<asp:BoundField DataField="星期" HeaderText="星期" />
<asp:BoundField DataField="节次" HeaderText="节次" />
<asp:BoundField DataField="课程" HeaderText="课程" />
<asp:BoundField DataField="考勤情况" HeaderText="考勤情况" />
<asp:CommandField HeaderText="编辑" ShowEditButton="True" />
</Columns>
</asp:GridView>
</div>
</div>
</form>
</body>
</html>
后台: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.SqlClient;
namespace 异动处理
{
public partial class UI : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ }
GridView1.DataSource = BLL.Yi.BLLset("select * from TestID");
GridView1.DataBind();
DropDownList1.Visible = false;
TextBox1.Visible = false;
GridView1.Visible = true;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList2.SelectedValue == "教工号查询")
{
TextBox1.Visible = true;
if (TextBox1.Visible == true)
{
DropDownList1.Visible = false;
}
}
if (DropDownList2.SelectedValue == "姓名查询")
{
TextBox1.Visible = true;
if (TextBox1.Visible == true)
{
DropDownList1.Visible = false;
}
}
if (DropDownList2.SelectedValue == "周次查询")
{
DropDownList1.Visible = true;
if (DropDownList1.Visible == true)
{
TextBox1.Visible = false;
}
}
if (DropDownList2.SelectedValue == "节次查询")
{
TextBox1.Visible = true;
if (TextBox1.Visible == true)
{
DropDownList1.Visible = false;
}
}
if (DropDownList2.SelectedValue == "课程查询")
{
TextBox1.Visible = true;
if (TextBox1.Visible == true)
{
DropDownList1.Visible = false;
}
}
if (DropDownList2.SelectedValue == "考勤情况查询")
{
TextBox1.Visible = true;
if (TextBox1.Visible == true)
{
DropDownList1.Visible = false;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (DropDownList2.SelectedValue == "教工号查询")
{
GridView1.DataSource = BLL.Yi.BLLset("SELECT * FROM TestID WHERE 教工号 = '" + TextBox1.Text + "'").Tables[0];
GridView1.DataBind();
}
if (DropDownList2.SelectedValue == "姓名查询")
{
GridView1.DataSource = BLL.Yi.BLLset("SELECT * FROM TestID WHERE 姓名 = '" + TextBox1.Text + "'").Tables[0];
GridView1.DataBind();
}
if (DropDownList2.SelectedValue == "周次查询")
{
GridView1.DataSource = BLL.Yi.BLLset("SELECT * FROM TestID WHERE 周次 = '" + DropDownList1.SelectedItem.Text + "'").Tables[0];
GridView1.DataBind();
}
if (DropDownList2.SelectedValue == "节次查询")
{
GridView1.DataSource = BLL.Yi.BLLset("SELECT * FROM TestID WHERE 节次 = '" + TextBox1.Text + "'").Tables[0];
GridView1.DataBind();
}
if (DropDownList2.SelectedValue == "课程查询")
{
GridView1.DataSource = BLL.Yi.BLLset("SELECT * FROM TestID WHERE 课程 = '" + TextBox1.Text + "'").Tables[0];
GridView1.DataBind();
}
if (DropDownList2.SelectedValue == "考勤情况查询")
{
GridView1.DataSource = BLL.Yi.BLLset("SELECT * FROM TestID WHERE 考勤情况 = '" + TextBox1.Text + "'").Tables[0];
GridView1.DataBind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
DataBind();
}
protected void update(int r)
{
string 教工号 = ((TextBox)(GridView1.Rows[r].Cells[0].Controls[0])).Text;
string 姓名 = ((TextBox)(GridView1.Rows[r].Cells[1].Controls[0])).Text;
string 周次 = ((TextBox)(GridView1.Rows[r].Cells[2].Controls[0])).Text;
string 星期 = ((TextBox)(GridView1.Rows[r].Cells[3].Controls[0])).Text;
string 节次 = ((TextBox)(GridView1.Rows[r].Cells[4].Controls[0])).Text;
string 课程 = ((TextBox)(GridView1.Rows[r].Cells[5].Controls[0])).Text;
string 考勤情况 = ((TextBox)(GridView1.Rows[r].Cells[6].Controls[0])).Text;
BLL.Yi.BLLset("update TestID set 节次='" + 节次 + "',课程='" + 课程 + "',考勤情况='" + 考勤情况 + "'where 教工号='" + 教工号 + "'");
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int r = e.RowIndex;
GridView1.EditIndex = -1;
update(r);
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
DataBind();
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList3.SelectedValue == "管理员")
{
GridView1.Visible = true;
}
if (DropDownList3.SelectedValue == "教师")
{
GridView1.Visible = false;
}
if (DropDownList3.SelectedValue == "学生")
{
GridView1.Visible = false;
}
}
}
}
为何更改数据后还是和没改一样
[解决办法]
if (!IsPostBack)
{ }
GridView1.DataSource = BLL.Yi.BLLset("select * from TestID");
GridView1.DataBind();
DropDownList1.Visible = false;
TextBox1.Visible = false;
GridView1.Visible = true;
if (!IsPostBack)
{GridView1.DataSource = BLL.Yi.BLLset("select * from TestID");
GridView1.DataBind();
DropDownList1.Visible = false;
TextBox1.Visible = false;
GridView1.Visible = true; }