I have a RadToolBar (tbActions) within a GridTemplateColumn in a RadGrid. When I click a button in tbActions, I want to access the ID column of the GridDataItem row that contains the tbActions that I just clicked in. How can I get that reference?
<
rad:RadGrid
...>
<MasterTableView ...>
<
Columns
>
<
rad:GridBoundColumn DataField="ID"
UniqueName
=
"ID" />
<!--...more columns...-->
<
rad:GridTemplateColumn
UniqueName
=
"Actions"
>
<
ItemTemplate
>
<
rad:RadToolBar
ID
=
"tbActions"
Orientation
=
"Horizontal"
runat
=
"server"
OnButtonClick
=
"tbActions_OnButtonClick"
>
<
Items
>
<
rad:RadToolBarButton
ImageUrl
=
"images/button1.png"
Value
=
"1"
/>
<
rad:RadToolBarButton
ImageUrl
=
"images/button2.png"
Value
=
"2"
/>
<
rad:RadToolBarButton
ImageUrl
=
"images/button3.png"
Value
=
"3"
/>
</
Items
>
</
rad:RadToolBar
>
</
ItemTemplate
>
</
rad:GridTemplateColumn
>
</
Columns
>
<
DetailTables
>
...
</
DetailTables
>
</
MasterTableView
>
</
rad:RadGrid
>
protected
void
tbActions_OnButtonClick(
object
sender, RadToolBarEventArgs e)
{
//How can I get a reference to the GridDataItem that contains the toolbar
//of the button that I just clicked?
//this is not working:
GridDataItem item = (GridDataItem)e.Item.ToolBar.Parent.Parent;
string id;
if
(e.Item.Value ==
"1"
)
{
id = item["ID"].Text;
//more code here, use ID for db update
}
else
if
(e.Item.Value ==
"2"
)
{
id = item["ID"].Text;
//more code here, use ID for db update
}
else
if
(e.Item.Value ==
"3"
)
{
id = item["ID"].Text;
//more code here, use ID for db update
}
}