Quick question - What's the best way to access a control in a nested GridTableView (specifically lblPassword below) in the code behind? The password is encrypted in the database and I need to decrypt before displaying on the web page.
<
telerik:RadGrid
runat
=
"server"
ID
=
"gridDatabases"
AutoGenerateColumns
=
"False"
GridLines
=
"None"
Skin
=
"Windows7"
Width
=
"100%"
DataSourceID
=
"LinqDataSourceDatabases"
OnItemDataBound
=
"gridDatabases_ItemDataBound"
>
<
MasterTableView
DataSourceID
=
"LinqDataSourceDatabases"
DataKeyNames
=
"ID"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"ID"
DataSourceID
=
"LinqDataSourceUsers"
runat
=
"server"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"ID"
MasterKeyField
=
"DatabaseDetailID"
/>
</
ParentTableRelation
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"UserName"
HeaderText
=
"User Name"
SortExpression
=
"UserName"
UniqueName
=
"UserName"
/>
<
telerik:GridTemplateColumn
HeaderText
=
"Password"
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblPassword"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
ExpandCollapseColumn
Visible
=
"True"
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"DatabaseName"
HeaderText
=
"Database"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
I thought I could use the OnItemDatabound event, like this, but I can't seem call FindControl to drill down to get to the nested label control. This is basically what I'm trying to accomplish, and this would work if the control wasn't in a nested table.
protected
void
gridUserDetails_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
{
GridDataItem gridItem = (GridDataItem)e.Item;
UserDetail userDetail = (UserDetail)gridItem.DataItem;
Label lblPassword = (Label)gridItem.FindControl(
"lblPassword"
);
string
decryptedPassword = DecryptPassword(userDetail.Password);
lblPassword.Text = decryptedPassword;
}
}
Any help is greatly appreciated! Thanks.