我用griview绑定了新闻的id,title,content,等字段。在griview中当我点击"编辑时"需要导航到B页面(已经实现),用session获取griview的主键,在B页面上写sql语句"select title,content from news where id='" +Session["index"]+ "'",难解决的是:在B页面把得到的title赋给textbox,content赋给FCKEditor。望高手指教!

解决方案 »

  1.   

    居然能查询到title
    不就textbox.Text = title吗?
      

  2.   

    在B页面的根据主键查出这条记录,然后把记录里的Title,Content等值赋给相应的控件不就可以了吗?
      

  3.   

    这样行不通,下面是我的代码:
      private void bind()
        {
            string sql = "select title,content from news where id='" +Session["index"]+ "'";
            SqlDataReader reader=DBHelper .reader (sql);
            if (reader.HasRows && reader.Read())
            {
                FCKeditor1.Value = reader["content"].ToString();
                TextBox1.Text = reader["title"].ToString();
         }
      

  4.   

    断点调试看reader中有没有值,走不走if (reader.HasRows && reader.Read())里面的程序
      

  5.   

    你调试看看
    确定reader["title"].ToString()是有值的吗?
      

  6.   

    在if (reader.HasRows && reader.Read())设置一个断点
    即光标移到这句,按F9
      

  7.   

    reader.HasRows是false,if条件进不去!
      

  8.   

    先验证sql是否正确    在检查DBHelper .reader (sql);
      

  9.   

    传ID呀,再跟据ID来得出title和Content。好搞。要不你把源码放出来吧
      

  10.   

    我说一下我的想法:
    1切定你的session中是有值的
      

  11.   

    是session出问题了,Session["index"]是空的,怎么才能解决呢?
      

  12.   

    Session["index"] 是object,转换到你的id类型试试
    字符型->Session["index"].ToString().Trim();
    整形->Convert.ToInt32(Session["index"].ToString().Trim());
      

  13.   

    在A页面传B页面时别用session,用参数传
    b.aspx?id=A页面去掉的id
      

  14.   

    : 
     得到griview中的主键并赋值给Session:
     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridView1.EditIndex = e.RowIndex;
            int index = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
            Session["index"] = index;
        }              
     DBHelper中的方法:
       public static SqlDataReader reader(string sql)
        {
            SqlConnection con = new SqlConnection(ConnectionString);
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader reader = cmd.ExecuteReader();
            
            return reader;
        }
    B页面:private void bind()
        {
            string sql = "select title,content from news where id='" +Session["index"]+ "'";
            SqlDataReader reader=DBHelper .reader (sql);
            if (reader.HasRows && reader.Read())
            {
                FCKeditor1.Value = reader["content"].ToString();
                TextBox1.Text = reader["title"].ToString();
            }        //FCKeditor1.DataBind();
           
        }
      

  15.   

    检查用session获取griview的主键这里Session["index"]的值获取了没
    检查用session获取griview的主键定义的Session["XXX"]里面的XXX是不是等于index
    看看是不是长时间没操作导致session丢失,修改webconfig延长session时效
      

  16.   

    你写入session的时候,获到值了吗?
      

  17.   


    不要用seeion吧。用B.aspx?id={0}
      

  18.   

    不要用seeion吧。用B.aspx?id=用绑定的代码获取ID值,同时B页面不要用datareader,用datatable不是更好?
      

  19.   

    为什么要用session呢?直接b.aspx?id= 在B页面直接Request.QueryString["id"]不更省事
      

  20.   

    select title,content from news where id="+Request.QueryString["id"]+"sqldataadapter da=new sqldataadapter(sql,conn)
    datatable dt=new datatable()
    da.fill(dt)
    if(dt.rows.count>0)
    {
    FCKeditor1.Value = dt.rows[0]["content"].tostring();
      TextBox1.Text = dt.rows[0]["title"].tostring();}
      

  21.   

    id可是griview的主键,
    在a页面GridView1_RowEditing写下
    a.aspx?id={"id"};这样不行吧!见笑了!!