定义了一个GridView在ItemTemplate里定义了一个linkbutton<asp:LinkButton ID="LinkBtton2" runat="server" OnClick="LinkButton2_Click" Text='<%# Bind("ProjectName") %>'></asp:LinkButton>可是在后台的一个方法中想调用Linkbutton2的text属性的值时 却遇到了问题    protected void LinkButton2_Click(object sender, EventArgs e) 
    {
        txt_projectname.Text =;       
        Panel1.Visible = true;
    }
想要把LinkBtton2的text的值赋给projectname的text 问题是找不到LinkBtton2这是怎么回事情呢?麻烦各位大大帮帮小弟

解决方案 »

  1.   

     protected void LinkButton2_Click(object sender, EventArgs e)  
      {
      txt_projectname.Text =;   
      Panel1.Visible = true;
      }不是这样写的
      

  2.   

    LinkBtton LinkBtton2= sender as LinkBtton;
      

  3.   

    gridview1_RowDataBound: 
    (LinkButton)e.Row.Cells[6].Controls[0]).Text
      

  4.   

    模板里的控件是不会被你直接找到的
    LZ现在的情况应该可以直接用object这个参数,这应该就是LinkBtton2
    你把类型转一下就可以取到Text了如果是在其它地方就要先确定GridView的行
    再通过行的FindControl方法来找到控件,再转型就OK了
      

  5.   

     linkbution  lbtn = sender as linkbution;
    txt_projectname.Text = lbtn.text;
      

  6.   

    你这样写(GridView.rows[i].FindControl("LinkBtton2") as LinkBtton).Text