Determine DDL value for dynamic column creation in oninit event

*爱你&永不变心* 提交于 2019-12-13 19:49:31

问题


Greetings, hopefully there is a simple solution for this complex problem. Please correct any misconceptions I have along the way. A while ago I wrote a GrivView with dynamic column capability. The columns are added in the OnInit page event so that they are added BEFORE the viewstate is applied. They are reapplied on every posting in this section of the page so that when the viewstate is applied changes that the user has made and not committed to the database are maintained. It also is required if you don’t want your viewstate control tree to get out of synch and blow everything up.

My current problem is that I am now tasked with doing essentially the same thing where the columns will be different based on a Drop Down List (I will recreate the GridView if the ddl changes, and the users will lose all work with a warning). How can I get the ID that is selected in the Drop Down List in the OnInit Event? My understanding is that when the user changes the value of the ddl on the client side a JavaScript “__doPostBack” call is fired. The page request is then sent to the server but by the time the new value is present in the event handler I am past the point where I need to add the columns.

I saw something I thought was promising when people were trying to determine what control caused a post back but that code relies on page.Request.Params.Get("__EVENTTARGET"); and page.Request.Form which are empty.

Should I look at the session state, try to ‘send’ the ID using client side manipulation, or some other method (Perhaps a sneaky way to look in the viewstate I am missing)?

Thanks for any ideas!!!


回答1:


A control's submitted value is available from the Request[] collection even if it appears that your form has not been reconstructed yet.

You should simply be able to get the selected value during Init() using the following:

string value = Request["myDropDownID"];


来源:https://stackoverflow.com/questions/827547/determine-ddl-value-for-dynamic-column-creation-in-oninit-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!