zoukankan      html  css  js  c++  java
  • 点击标题显示内容页(连上)

    前台:

    <%@ 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();
            }
        }
    }

  • 相关阅读:
    chrome Network 过滤和高级过滤
    python3 在webelement对象里面获取元素路径的方法
    Robot frawork关键字使用报错原因
    robotframework-autoitlibrary离线安装
    网络基础之网络协议篇
    eclipse查看jar包源代码
    对链接服务器进行查询
    数据库还原失败System.Data.SqlClient.SqlError: 无法执行 BACKUP LOG,因为当前没有数据库备份
    sqlserver创建链接服务器
    5.0jemter(英文版)录制脚本,进行压力测试
  • 原文地址:https://www.cnblogs.com/duanlinlin/p/2994399.html
Copyright © 2011-2022 走看看