One of the columns is the id of the loged in user.
This column is used in the SELECT command but I use Display="false" attribute in the GridBoundColumn tag so that it is not displayed.
How can I filter the results in the background so that I can see only the rows with a specific id?
I can get the id of the loged in user with this code :
MembershipUser
myObject = Membership.GetUser();
string UserID = myObject.ProviderUserKey.ToString();
5 Answers, 1 is accepted

You can set the DataKeyNames as the UserId column(say column1) and then check if the UserId matches the DataKeyValues for the row and according show/hide rows. Check out the code below for a clear picture of the same.
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource2" OnPreRender="RadGrid1_PreRender" > |
<MasterTableView DataSourceID="SqlDataSource2" DataKeyNames="UserID"> |
cs:
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
foreach (GridDataItem data in RadGrid1.Items) |
{ |
if (data.GetDataKeyValue("UserID").ToString() == UserID) |
{ |
data.Visible = true; |
} |
else |
{ |
data.Visible = false; |
} |
} |
} |
Thanks
Princy.

Here's what I tried :
protected
void RadGrid1_PreRender(object sender, EventArgs e)
{
MembershipUser myObject = Membership.GetUser();
string UserID = myObject.ProviderUserKey.ToString();
foreach (GridDataItem data in RadGrid1.Items)
{
if (data.GetDataKeyValue("UserID").ToString() == UserID)
{ data.Visible = true;
}
else
{ data.Visible = false;
} } } |
and I get the following error:
UserID is neither a DataColumn nor a DataRelation for table DefaultView

I forgot to change UserID with the column name I use in my database!
Thanx again for your help!

Is there any way to do the reverse thing?
What I mean is when a user adds a record his userid is added automatically to the record userid column.
Thank you very much for your immediate help!
Please check this article for more info how to provide default values for insert:
http://www.telerik.com/help/aspnet/grid/apiforcontrolling_net2.html
Kind regards,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.