初学C#+ASP.NET+Oracle时积累的备忘点滴
在asp.net中,如何回车触发指定按钮的事件?
假设:
<asp:TextBox id="TextBox1" runat="server" Width="240px"></asp:TextBox>
<asp:Button id="ButtonOK" runat="server" BorderWidth="1px" BorderColor="Purple" BorderStyle="Solid" Text="Search Site"></asp:Button>
解决方法:
在.aspx页面中添加:
<SCRIPT LANGUAGE="javascript">
function EnterKeyClick(button)
{
if (event.keyCode == 13)
{
event.keyCode=9;
event.returnValue = false;
document.all[button].click();
}
}
</SCRIPT>
在Page_Load事件中添加:
TextBox1.Attributes.Add("onkeydown","EnterKeyClick('ButtonOK');");
关于DATAGRID数据更改时点2次/行号跟不准/失去焦点/丢失e等一系列问题的解决办法:首先把数据连接/dataadater等信息全放到void bindgrid中,其他地方不用if(!ISPOSTBACK),在PAGELOAD的时候只用个
if (!IsPostBack)
{
BindGrid();
}
---------------------------------------------------------------------------------
例如: private void Page_Load(object sender, System.EventArgs e)
{ if (!IsPostBack)
{BindGrid();}
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{ DataGrid1.EditItemIndex = e.Item.ItemIndex;
BindGrid();
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{ DataGrid1.EditItemIndex = -1;
BindGrid();
}
void BindGrid()
{ oleDbDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind();
}