• 点击标题显示内容页(连上)


    前台:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebShowXx.aspx.cs" Inherits="GridWive.WebShowXx" %>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <center>
        <table>
        <tr><td><div id="divtitle" runat="server"></div></td></tr>
        <tr><td><div id="divcontent" runat="server"></div></td></tr>
        </table>
        </center>
        </form>
    </body>
    </html>

    后台:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Data;


    namespace GridWive
    {
        public partial class WebShowXx : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                    {
                        string id = Request.QueryString["id"];
                        LoadData(id);
                    }
                }
            }
            private void LoadData(string id)
            {
                string strcon = @"Data Source=PC-DLL;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=linlin";
                SqlConnection conn = new SqlConnection(strcon);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                //每次都显式打开
                conn.Open();
                string sqlstr = "SELECT NewsTitle,NewsContent FROM T_News1 WHERE Id=@id";
                cmd.CommandText = sqlstr;
                cmd.Parameters.AddWithValue("@id", id);
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                adapter.Fill(dt);
                cmd.Dispose();
                conn.Dispose();


                divtitle.InnerHtml = "<h2>" + dt.Rows[0]["NewsTitle"].ToString() + "</h2>";
                divcontent.InnerHtml = dt.Rows[0]["NewsContent"].ToString();
            }
        }
    }

  • 相关阅读:
    数据库备份与还原
    启明星产品与微软Active Directory活动目录集成说明
    启明星请假系统里,计算工作日的实现
    启明星会议室预定系统Outlook版开始支持Exchange2013与Office365版
    Jquery Mobile实例--利用优酷JSON接口读取视频数据
    高性能且线程安全的两种格式化日期方式
    将数列唯一值化后再求中值的效率比较 第一方案胜出,加索引后在近两百万数据中查出中值耗时0.176秒
    Oracle WITH 语句 语法
    新三种求数列中值SQL之效率再比拼
    rank,dense_rank和row_number函数区别
  • 原文地址:https://www.cnblogs.com/duanlinlin/p/2994399.html
Copyright © 2020-2023  润新知