我的DataGrid里有个模板列,里面放了两个LinkButton,点击它们分别进行编辑和删除操作
<ItemTemplate>
<asp:LinkButton id="btEdit" runat="server" CommandName="Edit">编辑</asp:LinkButton>
<asp:LinkButton id="btDelete" runat="server" CommandName="Delete">删除</asp:LinkButton>
</ItemTemplate>我想在后台的.cs文件里更改LinkButton显示的文字,比如想把“编辑”改为“123”,该如何改呢?我试了好多方法都不行,如:
btEdit.Text = "123";
DataGrid1.btEdit.Text = "123";
DataGrid1.Columns[0].btEdit.Text = "123";我是新手,上面的语句是自己想当然写的,大家要是觉得错误百出也不要见笑啊!

解决方案 »

  1.   

    for(int i=0;i<DataGrid.Items.Count;i++)
    {
      LinkButton _linkbutton=(LinkButton)DataGrid.Items[i].FindControl("btEdit");
      _linkbutton.Text="sth you want to sign";
    }
      

  2.   

    加在这里试试
    private void DtgUser_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {

    }
      

  3.   

    我知道了,我是在Page_Load里想改变它,所以不行。我改成在DataBind时改变,就可以了。
      

  4.   

    我试过可以,只要在绑定之后就行了,把测试代码给你参考一下
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!IsPostBack)
    DtgBinding();
    }
    private void DtgBinding()
    {
    DbControl _dbcontrol=new DbControl(); 
    Dtg.DataSource=_dbcontrol.USER_SELECT_ALL();
    Dtg.DataBind();
    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    for(int i=0;i<Dtg.Items.Count;i++)
    {
    LinkButton _linkbutton=(LinkButton)Dtg.Items[i].FindControl("btEdit");
    _linkbutton.Text="sth you want to sign";
    }
     
    }
      

  5.   

    用findcontrol方法定位控件,然后在itemdatabound方法来设置你索要的东西,记住列序数
      

  6.   

    如果我用VB的话,会遇到控件类型转换的问题啊,
    有没有什么办法,FindControl("btEdit");这边转换