Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I am trying to use a common Itemplate class for dynamic generation of Templated controls for both Gridview and Detailsview.I am using an approach similar to described
here[^]. However, during databinding event, I have to explicitly specify the type of control being binded. For e.g

DropDownList dropdown = (DropDownList)sender;
            GridViewRow container = (GridViewRow)dropdown.NamingContainer; <-- Problem lies here
            object dataValue = DataBinder.Eval(container.DataItem, _columnName);


Is there any option where i can use an interface to access the NamingContainer and pass it to the DataBinder.Eval function to extract the underlying data item value ?
Posted

1 solution

Got the solution, following is the code for the same. This works for any Templated control


IDataItemContainer container = (IDataItemContainer)txt.NamingContainer;
           object dataValue = DataBinder.Eval(container.DataItem, _columnName);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900