protected void DataList3_ItemCommand(object source, DataListCommandEventArgs e)
    {
        Session["id"] = DataList3.DataKeys[e.Item.ItemIndex].ToString();
        Response.Redirect("showpageA.aspx?id=" + Session["id"] + "");
       
    } 
为何这段代码不起作用,DataList包含了linkbutton并且在commandname属性已经设为select,运行时能够在DataList检索出相关信息,但连接不到指定页面,我的代码是按照教材上写的,堕书堕带的光盘源程序里一模一样的代码能够运行,而我写的不能够连接到指页面,望各位高手多多帮助,真诚的感谢!    
                              -------C#初学者

解决方案 »

  1.   

    1. F9设个断点, F5运行看有没有执行这个事件.
    2. 看一下, showpageA.aspx是否存在?  并且与本页面在同一个文件夹下面.
      

  2.   

    DataList3.DataKeys[e.Item.ItemIndex].ToString();把这个换成固定的值看看
      

  3.   

    1.看看DataList3_ItemCommand是否写在DataList的方法里
    2.还要加上if(CommandName=="select"){...};
      

  4.   

    DataList3.DataKeys[e.Item.ItemIndex].ToString();把这个换成固定的值,我试过了,没有用,
      

  5.   

    ["freeboy827()"]请问如何注册这个事件?
      

  6.   

    回复["MicroDeviser(‰絔纱湮→しovの·んeТ) "]:没有提示像错误一类的信息,按datalist里的linkbutton就是原地打转,没有发生变化
      

  7.   

    protected  void  DataList3_ItemCommand(object  source,  DataListCommandEventArgs  e)  
    好像根本没有运行过该事件,如何让该事件运行正常?谢谢!
     
      

  8.   

    我认为应该是showpageA.aspx这个页面 你有没有拷贝到程序的路径中去?他用的是相对路径
      

  9.   

    我曾经改成以下代码,也没有反应;
    protected void DataList3_ItemCommand(object source, DataListCommandEventArgs e)
        {
            Response.Redirect("http://www.baidu.com");
           
        }
     protected void DataList3_ItemCommand(object source, DataListCommandEventArgs e)
    这段代码是自己手动加进去的,这样能行吗?问题得不到解决急死了!!!!!
      

  10.   

    问题解决了,谢谢你们的关心!原来我没有在index.aspx的源视图里加进OnItemCommand="DataList3_ItemCommand 才导致点击linkbutton没有连接成功!谢谢!
      

  11.   

    恩,也可以不用在视图里添加OnItemCommand="DataList3_ItemCommand"

    private void InitializeComponent()
    {    
    this.ID = "div_mvlist";
    this.Load += new System.EventHandler(this.Page_Load);
             DataList3.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DataList3_ItemCommand);
    }