我有一张表,我可以从中获取GridView
控件的数据。根据某些条件,我需要将此行插入或更新到另一个表。如果一个条件为真,我需要更改LinkButton
中EditItemTemplate
的文本以插入,否则更新自己。如何更改LinkButton
中的RowCommand
文字?
请帮忙。
答案 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")