hi,
i'm working with a datagrid that's almost entirely composed of template columns (the implementation of it is unique enough that it's required). one of the template classes i've created defines a DropDownList control and adds it to the footer. this all works fine and well.
however, i'm a bit stumped as to how to go about getting the value of a selected item in the control. part of the problem is due to the fact that controll cannot be named prior to compiling. this is the default behavior of controls inside datagrids. interestingly enough, the ID property of the control gets the runtime assigned name of the control *added* to it. for instance, if in code i assign myDropDownList.ID = "foo", the ID of the control is really "foo:_controlNameAssignedDuringHTMLBuild". that being said, i can't use the Item.FindControl method to extract the value of the control.
one sloppy way around this is to use the dropdownlist's events and pass a function pointer to the template ctor (i'm doing this for the button handlers in the datagrid). for example, the datagrid is defined on myPage.aspx.cs. this same file defines a function foo() which will be called when the dropdownlist's selectedIndex is changed. when creating the template column with the dropdown, i pass a function pointer (a delegate in C# speak) to my template object's ctor and use it for assignment to the dropdownlist's SelectIndexChanged event.
the event handler can store the value to some type of state variable i guess.
this'll work, however, the extra (non-validating) postback plus the state memory are more baggage than i was hoping for. i'm guessing there's gotta be a cleaner, more direct way to do this.
any thoughts on this? help is greatly appreciated. thanks!
..:: mirirom ::..
i'm working with a datagrid that's almost entirely composed of template columns (the implementation of it is unique enough that it's required). one of the template classes i've created defines a DropDownList control and adds it to the footer. this all works fine and well.
however, i'm a bit stumped as to how to go about getting the value of a selected item in the control. part of the problem is due to the fact that controll cannot be named prior to compiling. this is the default behavior of controls inside datagrids. interestingly enough, the ID property of the control gets the runtime assigned name of the control *added* to it. for instance, if in code i assign myDropDownList.ID = "foo", the ID of the control is really "foo:_controlNameAssignedDuringHTMLBuild". that being said, i can't use the Item.FindControl method to extract the value of the control.
one sloppy way around this is to use the dropdownlist's events and pass a function pointer to the template ctor (i'm doing this for the button handlers in the datagrid). for example, the datagrid is defined on myPage.aspx.cs. this same file defines a function foo() which will be called when the dropdownlist's selectedIndex is changed. when creating the template column with the dropdown, i pass a function pointer (a delegate in C# speak) to my template object's ctor and use it for assignment to the dropdownlist's SelectIndexChanged event.
the event handler can store the value to some type of state variable i guess.
this'll work, however, the extra (non-validating) postback plus the state memory are more baggage than i was hoping for. i'm guessing there's gotta be a cleaner, more direct way to do this.
any thoughts on this? help is greatly appreciated. thanks!
..:: mirirom ::..