⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 news.aspx

📁 本文件为ASP开发的在线播放系统,挺不错的,创建数据需按照说明进行创建,祝你成功!
💻 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">

/*************************************************
* 模块: news.aspx	
* 作者: miles	
* 修改: 1/30/2001
* 目的: news table maintain
* 参数: none
* 数据: sel: news
*       ins: news
*       del: news
*       upt: none
***************************************************/

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 news (news_id,news_head) values (@news_id,@news_head)";
	SqlCommand myCommand = new SqlCommand(insertCmd, myConnection);
	myCommand.Parameters.Add(new SqlParameter("@news_id", SqlDbType.VarChar, 50));
	myCommand.Parameters["@news_id"].Value = news_id.Value;        
	myCommand.Parameters.Add(new SqlParameter("@news_head", SqlDbType.VarChar, 50));
	myCommand.Parameters["@news_head"].Value = news_head.Value;
	myConnection.Open();
	try {
	   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 news where news_id = @news_id";
	SqlCommand myCommand = new SqlCommand(deleteCmd, myConnection);
	myCommand.Parameters.Add(new SqlParameter("@news_id", SqlDbType.VarChar, 50));
	myCommand.Parameters["@news_id"].Value = MyDataGrid.DataKeys[(int)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 BindGrid() {
   try {
	SqlDataAdapter myCommand = new SqlDataAdapter("select * from news", myConnection);
	DataSet ds = new DataSet();
	myCommand.Fill(ds, "news");
	MyDataGrid.DataSource=ds.Tables["news"].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">最新消息代码:</span><BR><input type="text" id="news_id" value="000" runat="server"></FONT></TD>
	      <TD VALIGN="top" ALIGN="left"><span class="REQUIREDFIELD">最新消息名称:</span><BR><input type="text" id="news_head" value="000" runat="server"></FONT></TD>
	      <TD VALIGN="top" ALIGN="left"><FONT FACE="Verdana,Helvetica,Arial" SIZE=1>&nbsp;<BR>        <input type="submit" OnServerClick="Add_Click" value="新增" runat="server"></FONT></TD>				              
            </tr>
           <TR>
	     <TD ><asp:RequiredFieldValidator ControlToValidate="news_id" Display="Static" ErrorMessage="*:不可空白" runat=server/></TD>
	     <TD ><asp:RequiredFieldValidator ControlToValidate="news_head" 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"
      OnDeleteCommand="MyDataGrid_Delete"
      DataKeyField="news_id"
      AutoGenerateColumns="false"
    >

      <Columns>
	 <asp:ButtonColumn Text="删除" CommandName="Delete"  ButtonType="PushButton" />
	<asp:TemplateColumn HeaderText="最新消息代码" >
          <ItemTemplate>
            <a href="news_upt.aspx?news_id=<%# DataBinder.Eval(Container.DataItem, "news_id") %>"><asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "news_id") %>'/> </a>
          </ItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn HeaderText="最新消息名称" SortExpression="news_head">
          <ItemTemplate>
            <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "news_head") %>'/>
          </ItemTemplate>
        </asp:TemplateColumn>
      </Columns>
    </ASP:DataGrid>

  </form>
<!-- #include virtual="/include/footer.inc" -->
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -