哪位高手帮我看看,DataGrid1的事件为什么不执行
jgjzj 2005-07-31 05:30:48 哪位高手帮我看看,DataGrid1的事件为什么不执行。
代码如下:
protected Infragistics.WebUI.UltraWebTab.UltraWebTab UltraWebTab1;
protected static string id = null;
protected static string id2 = null;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
{
ReadAndPrintClass1();
ReadAndPrintClass2();
}
}
private void ReadAndPrintClass1()
{
Sql sqlserve = new Sql();
DataSet ds = sqlserve.ReadData("Class1List");
DataGrid dg = (DataGrid)UltraWebTab1.FindControl("DataGrid1");
dg.DataSource = ds.Tables[0];
dg.DataBind();
}
private void ReadAndPrintClass2()
{
Sql sqlserve = new Sql();
DataSet ds2 = sqlserve.ReadData("Class2List");
DataGrid dg2 = (DataGrid)UltraWebTab1.FindControl("DataGrid2");
dg2.DataSource = ds2.Tables[0];
dg2.DataBind();
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
DataGrid dg2 = (DataGrid)UltraWebTab1.FindControl("DataGrid2");
dg2.DeleteCommand += new DataGridCommandEventHandler(dg2_DeleteCommand);
dg2.EditCommand += new DataGridCommandEventHandler(dg2_EditCommand);
DataGrid dg = (DataGrid)UltraWebTab1.FindControl("DataGrid1");
dg.DeleteCommand += new DataGridCommandEventHandler(dg_DeleteCommand);
dg.EditCommand += new DataGridCommandEventHandler(dg_EditCommand);
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void dg_EditCommand(object source, DataGridCommandEventArgs e)
{
Panel pl = (Panel)UltraWebTab1.FindControl("Panel1");
pl.Visible = true;
id = e.Item.Cells[0].Text;
TextBox tb1 = (TextBox)UltraWebTab1.FindControl("TextBox1");
tb1.Text = id;
TextBox tb2 = (TextBox)UltraWebTab1.FindControl("TextBox2");
tb2.Text = e.Item.Cells[1].Text;
ReadAndPrintClass1();
}
private void dg2_EditCommand(object source, DataGridCommandEventArgs e)
{
Panel pl2 = (Panel)UltraWebTab1.FindControl("Panel2");
pl2.Visible = true;
id2 = e.Item.Cells[0].Text;
TextBox tb3 = (TextBox)UltraWebTab1.FindControl("TextBox3");
tb3.Text = id2;
TextBox tb4 = (TextBox)UltraWebTab1.FindControl("TextBox4");
tb4.Text = e.Item.Cells[1].Text;
ListClass1();
DropDownList ddl = (DropDownList)UltraWebTab1.FindControl("DropDownList1");
ddl.SelectedValue = e.Item.Cells[3].Text;
}
private void dg_DeleteCommand(object source, DataGridCommandEventArgs e)
{
Sql sqlserve = new Sql();
if (sqlserve.ChangeData("DelClass1Single",e.Item.Cells[0].Text))
{
Label lb = (Label)UltraWebTab1.FindControl("Label3");
lb.Text = "删除数据成功";
}
else
{
Label lb = (Label)UltraWebTab1.FindControl("Label3");
lb.Text = "删除数据失败";
}
id = "";
ReadAndPrintClass1();
}
private void dg2_DeleteCommand(object source, DataGridCommandEventArgs e)
{
Sql sqlserve = new Sql();
if (sqlserve.ChangeData("DelClass2Single",e.Item.Cells[0].Text))
{
Label lb7 = (Label)UltraWebTab1.FindControl("Label7");
lb7.Text = "成功删除数据";
}
else
{
Label lb7 = (Label)UltraWebTab1.FindControl("Label7");
lb7.Text = "删除数据失败";
}
ReadAndPrintClass2();
}
private void ListClass1()
{
Sql sqlserve = new Sql();
DataSet ds = sqlserve.ReadData("Class1List");
DropDownList ddl = (DropDownList)UltraWebTab1.FindControl("DropDownList1");
ddl.DataSource = ds.Tables[0];
ddl.DataTextField = "cla1_name";
ddl.DataValueField = "cla1_id";
ddl.DataBind();
}