开发者

PostbackUrl of dynamic GridViews not what I think they should be

I have a couple GridViews that are dynamically created and placed into a PlaceHolder. When I mouse over the Select button, it shows __doPostBack('ctl00$bodyPlaceHolder$ctl0X','Select$Y'), where X = what I think is the GridView/Control index for the page and Y = row number of that GridView.

Since it is dynamically creating the GridViews, it makes sense that names them ctl0X, but on the PostBack how do I use this information?

I wouldn't even have this problem if adding the SelectedIndexChanged EventHandler worked, but it never gets called.

I found one other question like this, but the answer involved adding a GridView within my GridViews, which would also have to be dynamic, which brings me back to the original problem.

Edit

Okay, so I set gridViewDynamic.ID = "blahblah" + r.LastName, thus giving each GridView a unique name, so on mouseover in the page I get __doPostBack('ctl00$bodyPlaceHolder$blahblahSmith',Select$Y, I still can't access the items on PostBack because they no longer exist. So, I added the same GridView creation code to an if(IsPostBack), then called GridView gView = (GridView)this.Page.FindControl(blahblahSmith). Great, gVi开发者_StackOverflow中文版ew isn't null. But all the data in the rows are. Calling gView.Rows[0] returns null.


Use Page.FindControl("TheNameYouGaveTheDynamicGridView")

GridView grid = Page.FindControl("TheNameYouGaveTheDynamicGridView") as GridView;

If you are using MasterPages, you need to take a different approach to find the control on the page, but it is the same premise.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜