views:

428

answers:

2

Hi,

I have a table from which i am getting my data to the GridView control. I need to Insert Or Update this row to another table, according to some condition. If one condition is true, i need to change the text of the LinkButton in EditItemTemplate to insert, else to update itself. How can i change the text of LinkButton in RowCommand?

Please help.

A: 

You can for example set the text of the link button in a method of your code-behind class:

<!--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";
}

or

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

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