开发者

LoginView not display databound control

I've come to a scenario where I need to databind something only if the user is logged in. To do this I am using the LoginView control to display a Login control when they are not logged in and a GridView control when they are logged in. However, when I databind to the GridView object in the LoginView, nothing ever gets displayed. I have been debugging it and I am databinding it to a DataTable that definitely has data in it, however nothing shows up.

Here is some of the code: if (User.Identity.IsAuthenticated) { ((GridView)LoginView1.FindControl("GridView1")).DataSource = dt; ((GridView)LoginView1.FindControl("GridView1")).DataBind(); }

Is there a particular reason that 开发者_开发问答this should not work? Is it bad practice?


why do you use User.Identity.IsAuthenticated when your GridView is in the LoginView Control? Both things do sort of the same. I think you have a race-condition here.

Use the LoginViewControl in your ASPX-page OR the if/Else statement with the User.Identity.IsAuthenticated in your code behind.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜