Thursday, June 3, 2010

Programatically changing the text of a GridButtonColum / GridEditCommandColumn / CommandItem

Task: Be able of programatically change the text of a Grid's GridButtonColum, GridEditCommandColumn and CommandItem.

Valid for: RadGrid and DataGrid

Process:
Firstly, identify the event. I've decided to use teh ItemDataBound, but it can be done using the PreRender as well.

Secondly, identify the Grid control and the columns id and types of what we need to modify.

Thirdly, do the programming in the chosen event. In this case ItemDatabound:

1 If (TypeOf e.Item Is GridHeaderItem) Then
2 Dim columnView As GridButtonColumn = CType(e.Item.OwnerTableView.GetColumn("View"
), GridButtonColumn)
3 columnView.Text = GetCommonMessage(strGlobalUser, "View"
, strLang)
4 Dim columnEdit As GridEditCommandColumn = CType(e.Item.OwnerTableView.GetColumn("EditCommandColumn"
), GridEditCommandColumn)
5 columnEdit.EditText = GetCommonMessage(strGlobalUser, "Edit"
, strLang)
6 End If

7

8
9 If e.Item.ItemType = GridItemType.CommandItem Then
10 CType(e.Item.FindControl("lblAddProduct"), Label).Text = GetCommonMessage(strGlobalUser, "AddNewLine"
, strLang)
11 CType(e.Item.FindControl("lnkAddProduct"), LinkButton).ToolTip = GetCommonMessage(strGlobalUser, "ClickHereToAddaNewLine"
, strLang)
12 End If

Finally, The code is ready to test.


No comments:

Post a Comment