2009-07-03 44 views
0

我有一個表格,我從中獲取我的數據到GridView控件。根據某些條件,我需要將此行插入或更新到另一個表。如果一個條件成立,我需要更改LinkButton的文本EditItemTemplate以插入,否則自行更新。如何更改RowCommandLinkButton的文字?要更改EditItemTemplate中的LinkBut​​ton的文本

請幫忙。

+0

接受請其中一個答案 – abatishchev 2010-05-09 09:57:42

回答

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"; 
} 
0
Dim GridView1 As GridView = New GridView 
Dim condition As Boolean = False 

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