在EditItemTemplate中更改LinkBut​​ton的文本

时间:2009-07-03 10:58:42

标签: asp.net vb.net gridview

我有一张表,我可以从中获取GridView控件的数据。根据某些条件,我需要将此行插入或更新到另一个表。如果一个条件为真,我需要更改LinkButtonEditItemTemplate的文本以插入,否则更新自己。如何更改LinkButton中的RowCommand文字?

请帮忙。

2 个答案:

答案 0 :(得分:0)

例如,您可以在代码隐藏类的方法中设置链接按钮的文本:

<!--markup-->
<asp:LinkButton Text='<%# GetLinkButtonText(Container.DataItem) %>' ...>

//code-behind
protected string GetLinkButtonText(object dataItem)
{
  // dataItem is the item bound to the current row
  // check conditions
  return "text for link button";
}

<!--markup-->
<asp:LinkButton Text='<%# GetLinkButtonText(Eval("SomeField")) %>' ...>

//code-behind
protected string GetLinkButtonText(object field)
{
  // field contains the value of the field specified in the markup
  // check conditions, e.g:
  if ((int)field > 10)
    return "some text";
  else
    return "some other text";
}

答案 1 :(得分:0)

Dim GridView1 As GridView = New GridView
Dim condition As Boolean = False

CType(GridView1.FindControl("LinkButton1"), LinkButton).Text = If(condition, "Insert", "Update")