0
我有一個表格,我從中獲取我的數據到GridView
控件。根據某些條件,我需要將此行插入或更新到另一個表。如果一個條件成立,我需要更改LinkButton
的文本EditItemTemplate
以插入,否則自行更新。如何更改RowCommand
中LinkButton
的文字?要更改EditItemTemplate中的LinkButton的文本
請幫忙。
我有一個表格,我從中獲取我的數據到GridView
控件。根據某些條件,我需要將此行插入或更新到另一個表。如果一個條件成立,我需要更改LinkButton
的文本EditItemTemplate
以插入,否則自行更新。如何更改RowCommand
中LinkButton
的文字?要更改EditItemTemplate中的LinkButton的文本
請幫忙。
例如,您可以設置鏈接按鈕的文本中的代碼隱藏類中的方法:
<!--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";
}
Dim GridView1 As GridView = New GridView
Dim condition As Boolean = False
CType(GridView1.FindControl("LinkButton1"), LinkButton).Text = If(condition, "Insert", "Update")
接受請其中一個答案 – abatishchev 2010-05-09 09:57:42