在Datalist中通过点击某条目录跳转页面时用URL进行传值的方法

//起始页前台代码


         
            
                   
                       
                             ◎ <%#Eval("Article_Title")%>

                        [<%#((DateTime)Eval("Release_Time")).ToShortDateString()%>]
                   

               

         

 

//起始页后台代码

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string keyStr = this.DataList1.DataKeys[e.Item.ItemIndex].ToString();
        Response.Redirect("Word.aspx?Num=" + keyStr + "&tablename=news");
    }

 

//目标页后台代码

string ArtId = Request.QueryString["Num"].ToString();
string Tablename = Request.QueryString["tablename"].ToString();

ShowSameInfo(this.lab_title, this.lab_Smtitle, this.txt_info, this.lab_username, ArtId, Tablename);

 

// 方法

   #region  显示文章或新闻详情
    ///


    /// 显示文章详情
    ///

    /// 大标题
    /// 小标题
    /// 正文
    /// 作者
    /// 文章ID
    /// 表名

    public void ShowSameInfo(Label title1, Label title2, TextBox article, Label username, string articleId, string tablename)
    {
        string str;
        if (tablename == "news")
            str = "select Article_Title,Article,username,Release_Time from " + tablename + " where id=" + articleId + "";
        else
            str = "select id,Article_Title,Article,associator_RealName,Release_Time from Article,associator where id=" + articleId + " and associator.associator_ID=Article.associator_ID";
        SqlDataReader dr = dbs.ReturnDataReader(str);
        while (dr.Read())
        {
            title1.Text = title2.Text = dr["Article_Title"].ToString();
            article.Text = dr["article"].ToString();
            if (tablename == "news")
                username.Text = dr["username"].ToString();
            else
                username.Text = dr["associator_RealName"].ToString();
        }
        dr.Close();
    }
    #endregion

 

你可能感兴趣的:(在Datalist中通过点击某条目录跳转页面时用URL进行传值的方法)