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

  • 相关阅读:
    JDBC原理及常见错误分析
    response,session,cookie
    Activity LifeCycle (安卓应用的运行机制)
    简单的接口取数据渲染到图表
    图表里面双重下拉框进行判断
    用js方式取得接口里面json数据的key和value值
    一个div多个图表共用一个图例
    一个页面多图表展示(四个div的方式)
    vue组件之子组件和父组件
    根据判断对颜色进行改变
  • 原文地址:https://www.cnblogs.com/duanlinlin/p/2994399.html
Copyright © 2011-2022 走看看