📄 job_title.aspx
字号:
<!-- #include virtual="/include/pagedirective.inc" -->
<!-- #include virtual="/include/imports.inc" -->
<!-- #include virtual="/include/common_function.inc" -->
<html>
<head>
<link REL="StyleSheet" HREF="/css/standard.css" >
<script language="C#" runat="server">
/*************************************************
* 模块: job_title.aspx
* 作者: vivid
* 修改: 2/1/2001
* 目的: job_title table maintain
* 参数: none
* 数据: sel: job_title
* ins: job_title
* del: job_title
* upt: job_title
***************************************************/
SqlConnection myConnection;
private void Page_Load(Object Src, EventArgs E) {
try {
myConnection = new SqlConnection(ConfigurationSettings.AppSettings["edu"]);
if (!IsPostBack)
BindGrid();
}
catch (System.Exception e){
ErrorHandler(e.ToString());
}
}
private void Add_Click(Object sender, EventArgs E) {
try{
string insertCmd = "insert into job_title values (@job_title_id,@job_title_name)";
SqlCommand myCommand = new SqlCommand(insertCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@job_title_id", SqlDbType.VarChar, 50));
myCommand.Parameters["@job_title_id"].Value = job_title_id.Value;
myCommand.Parameters.Add(new SqlParameter("@job_title_name", SqlDbType.VarChar, 50));
myCommand.Parameters["@job_title_name"].Value = job_title_name.Value;
try {
myConnection.Open();
myCommand.ExecuteNonQuery();
MessageSQLInsDone();
}
catch (System.Data.SqlClient.SqlException e) {
SQLErrorHandler(e);
}
myConnection.Close();
BindGrid();
}
catch (System.Exception e){
ErrorHandler(e.ToString());
}
}
private void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs E) {
try{
String deleteCmd = "delete from job_title where job_title_id = @job_title_id";
SqlCommand myCommand = new SqlCommand(deleteCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@job_title_id", SqlDbType.VarChar, 50));
myCommand.Parameters["@job_title_id"].Value =MyDataGrid.DataKeys[E.Item.ItemIndex];
myConnection.Open();
try {
myCommand.ExecuteNonQuery();
MessageSQLDelDone();
}
catch (System.Data.SqlClient.SqlException e) {
SQLErrorHandler(e);
}
myConnection.Close();
BindGrid();
}
catch (System.Exception e) {
ErrorHandler(e.ToString());
}
}
private void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs E) {
try{
MyDataGrid.EditItemIndex = E.Item.ItemIndex;
BindGrid();
}
catch (System.Exception e) {
ErrorHandler(e.ToString());
}
}
private void MyDataGrid_Cancel(Object sender, DataGridCommandEventArgs E) {
try{
MyDataGrid.EditItemIndex = -1;
BindGrid();
}
catch (System.Exception e) {
ErrorHandler(e.ToString());
}
}
private void MyDataGrid_Update(Object sender, DataGridCommandEventArgs E) {
try{
if (Page.IsValid) {
string updateCmd = "update job_title set job_title_name = @job_title_name where job_title_id = @job_title_id";
SqlCommand myCommand = new SqlCommand(updateCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@job_title_id", SqlDbType.VarChar, 50));
myCommand.Parameters["@job_title_id"].Value = MyDataGrid.DataKeys[E.Item.ItemIndex];
myCommand.Parameters.Add(new SqlParameter("@job_title_name", SqlDbType.VarChar, 50));
myCommand.Parameters["@job_title_name"].Value = ((TextBox)E.Item.FindControl("edit_job_title_name")).Text;
myConnection.Open();
try {
myCommand.ExecuteNonQuery();
MessageSQLUptDone();
MyDataGrid.EditItemIndex = -1;
}
catch (System.Data.SqlClient.SqlException e) {
SQLErrorHandler(e);
}
myConnection.Close();
BindGrid();
}
}
catch (System.Exception e) {
ErrorHandler(e.ToString());
}
}
private void BindGrid() {
try{
SqlDataAdapter myCommand = new SqlDataAdapter("select * from job_title ", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "job_title");
MyDataGrid.DataSource=ds.Tables["job_title"].DefaultView;
MyDataGrid.DataBind();
}
catch (System.Exception e){
ErrorHandler(e.ToString());
}
}
</script>
</head>
<body style="font: 10pt verdana">
<!-- #include virtual="/include/header.inc" -->
<form runat="server">
<table width=100% cellspacing=0 cellpadding=0>
<tr>
<td align="center" class="CONTENTTITLE" width="100%" bgcolor="D3C9C7">
职称数据维护
</td>
</tr>
<tr>
<td>
<span id="Message" EnableViewState="false" class="MESSAGE" runat="server"/>
</td>
</tr>
<tr>
<td colspan="10" bgcolor="#aaaadd" style="font:10pt verdana">新增:</td>
</tr>
</table>
<table style="font: 8pt verdana">
<tr>
<TD VALIGN="top" ALIGN="left"><span class="REQUIREDFIELD">职称代码:<BR><input type="text" id="job_title_id" value="000" runat="server"></FONT></TD>
<TD VALIGN="top" ALIGN="left"><span class="REQUIREDFIELD">职称名称:</LABEL><BR><input type="text" id="job_title_name" value="000" runat="server"></FONT></TD>
<TD VALIGN="top" ALIGN="left"><FONT FACE="Verdana,Helvetica,Arial" SIZE=1> <BR> <input type="submit" OnServerClick="Add_Click" value="新增" runat="server"></FONT></TD>
</tr>
<TR>
<TD > <asp:RequiredFieldValidator ControlToValidate="job_title_id" Display="Static" ErrorMessage="*:不可空白" runat=server/></TD>
<TD > <asp:RequiredFieldValidator ControlToValidate="job_title_name" Display="Static" ErrorMessage="*:不可空白" runat=server/></TD>
</TR>
</table>
<table style="font: 8pt verdana" width=100% >
<tr>
<td colspan="5" bgcolor="#aaaadd" style="font:10pt verdana">修改/删除:</td>
</tr>
</table>
<ASP:DataGrid id="MyDataGrid" runat="server"
BackColor="#F4FFF4"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="lightblue"
OnEditCommand="MyDataGrid_Edit"
OnCancelCommand="MyDataGrid_Cancel"
OnUpdateCommand="MyDataGrid_Update"
OnDeleteCommand="MyDataGrid_Delete"
DataKeyField="job_title_id"
AutoGenerateColumns="false"
>
<Columns>
<asp:EditCommandColumn
EditText="修改"
CancelText="取消"
UpdateText="储存"
ItemStyle-Wrap="false"
ButtonType=" PushButton" />
<asp:ButtonColumn
Text="删除"
CommandName="Delete"
ButtonType="PushButton" />
<asp:BoundColumn
HeaderText="职称代码"
SortExpression="job_title_id"
ReadOnly="True"
DataField="job_title_id"
ItemStyle-Wrap="false"/>
<asp:TemplateColumn
HeaderText="职称名称"
SortExpression="job_title_name">
<ItemTemplate>
<asp:Label runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "job_title_name") %>'/>
</ItemTemplate>
<EditItemTemplate>
<nobr>
<asp:TextBox runat="server"
id="edit_job_title_name"
Text='<%# DataBinder.Eval(Container.DataItem, "job_title_name") %>'/>
<asp:RequiredFieldValidator id="job_title_name_ReqVal"
ControlToValidate="edit_job_title_name"
Display="Dynamic"
Font-Name="Verdana" Font-Size="12"
runat=server>
*
</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</ASP:DataGrid>
</form>
<p>
<!-- #include virtual="/include/footer.inc" -->
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -