To change the text of LinkButton in EditItemTemplate

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.

Answers


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

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

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

Need Your Help

Rails commands on windows have a delay before execution

ruby-on-rails-3 windows-7 cmd

I am using Ruby on Rails under windows, installed with railsinstaller. Everything works fine, except that any command such as rails console or bundle exec rake db:migrate takes on average 8 seconds