我的gridview的GridView1_RowCommand没有触发
刚刚解决玩gridview的翻页问题,发现点击GridView中的linkbutton也没效果了,追踪了一下GridView1_RowCommand事件根本没有触发。。。
public partial class dzEmployee : System.Web.UI.Page
{
dzDB.Sql mySql = new dzDB.Sql();
public DataSet myDataSet = new DataSet();
public static string sqlstr = "";
public static string table = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
table = "Sys_Employee";
sqlstr = "select eId,eName,eSex,eSection,ePosition,eProId,eTele from Sys_Employee";
GridView_DataBind(sqlstr, table);
DroplistdownBind(DropDownList1, "Flag", "0", "Sys_Dictionary", "Id", "DictionaryName");
}
}
private void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = e.Row.FindControl("Label3") as Label;
Label lbl2 = e.Row.FindControl("Label4") as Label;
Label lbl3 = e.Row.FindControl("Label5") as Label;
SqlDataReader myReader = mySql.myReader("select DictionaryName from Sys_Dictionary where Id='" + lbl.Text + "'");
if (myReader.Read())
{
lbl.Text = myReader.GetString(0);
}
myReader = mySql.myReader("select PositionName from Sys_DicPosition where Id='" + lbl2.Text + "'");
if (myReader.Read())
{
lbl2.Text = myReader.GetString(0);
}
myReader = mySql.myReader("select ItemPlace from Sys_Item where ItemID='" + lbl3.Text + "'");
if (myReader.Read())
{
lbl3.Text = myReader.GetString(0);
}
myReader.Dispose();
}
}
private void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "btn")
{
string eId = e.CommandArgument.ToString();
Response.Redirect("EmployEdit.aspx?eId=" + eId);
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView_DataBind(sqlstr, table);
}
private void GridView_DataBind(string sqlstr,string table)
{
myDataSet = mySql.createDataSet(sqlstr, table);
GridView1.DataSource = myDataSet.Tables[table].DefaultView;
GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
// GridView1.DataKeys = "eId";
GridView1.AllowPaging = true;
GridView1.PageSize = 10;
GridView1.DataBind();
GridView1.RowCommand += new GridViewCommandEventHandler(GridView1_RowCommand);
}
protected void Button1_Click(object sender, EventArgs e)
{
string eName = TextBox1.Text;
try
{
sqlstr = "select eId,eName,eSex,eSection,ePosition,eProId,eTele from Sys_Employee where eName like '%" + eName + "%'";
table = "Sys_Employee";
GridView_DataBind(sqlstr, table);
}
catch
{
}
}
请问是为什么,以前都能触发的。。。