how to bind data to DropDownList in custom control

Hello,

I'm working on a custom control.  I want to add ej:DropDownList inside formview in custom control.  I also want to use a function of code behind as selectMethod.  I set custom control class Name into TypeName attribute in ej:DropDownList, but doesn't work.  It ends up error.
In my case, data type for binding is from another class from other assembly.  Method I use and DataType for bind is in different class.

 ObjectDataSource 'obj1' could not find a non-generic method 'eStudio.ucPx.TitleCode_GetItems' that has no parameters.

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ucPx.ascx.vb" Inherits="eStudio.ucPx" %>

<asp:FormView >
     <EditTemplate>
                <ej:DropDownList ID="TitleCodeDropDownList" runat="server"
                        DataTextField="ShortDescription"
                        DataValueField="TitleCode"   DataSourceID="obj1"  ></ej:DropDownList>
                    <asp:ObjectDataSourceID="obj1" runat="server" TypeName="eStudio.ucPx"      SelectMethod="eStudio.ucPx.TitleCode_GetItems"></asp:ObjectDataSource>
   </EditTemplate>
          :
          :
</asp:FormView >



ucPx.ascx.vb

Partial Public Class ucPx
    Inherits UserControlClass

      Public Function TitleCode_GetItems() As List(Of DAL.Data.Title)
             Using db = New MemberData(Me.User)
                 Dim q = (From item In db.Titles
                     Select item).ToList
                 Return q
             End Using
         End Function

End Class





7 Replies

KV Karthikeyan Viswanathan Syncfusion Team July 11, 2018 09:19 AM UTC

Hi Yukiko Imazu, 

  Thanks for contacting Syncfusion support. 

We have validated your shared code example. We suspect that the issue related to assignment of SelectMethod  property in ObjectDataSource. You don’t need to assign a method with namespace. You can directly assign a method into that property. 

Please find the below code example: 

<code> 

<asp:ObjectDataSource ID="obj1" runat="server" TypeName="eStudio.ucPx" SelectMethod="TitleCode_GetItems"></asp:ObjectDataSource> 

</code> 

Regards, 
Karthikeyan V. 



YI Yukiko Imazu July 11, 2018 02:35 PM UTC

Thank you Karthikeyan,

I set TypeName and SelectMethod property as you mentioned.  Objectdatasource error that I asked was solved.
However, other errors come up.


TargetInvocationException
   Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments,
Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at
Syncfusion.JavaScript.Shared.Serializer.SerializeObject.BuildJsonDictionary(Object obj) at
Syncfusion.JavaScript.Shared.Serializer.SerializeObject.SerializeToJson(Object inputObject, String serializerMode, Object serializerSettings) at
Syncfusion.JavaScript.Shared.Serializer.SerializeObject.SerializeToJson(Object input, String ID) at Syncfusion.JavaScript.Control.Serialize(Object model) at
 Syncfusion.JavaScript.Control.RenderJson() at Syncfusion.JavaScript.Control.Raw() at Syncfusion.JavaScript.Control.ToHtmlString() at
 Syncfusion.JavaScript.Web.DropDownList.Render(HtmlTextWriter writer) at
 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at
ASP.ucperson_ascx.__Render__control7(HtmlTextWriter __w, Control parameterContainer) at
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at
System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter writer) at
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at 


When I remove ej:dropdownlist, this error doesn't happen.
The code I use is the same as I posted yesterday. 





KV Karthikeyan Viswanathan Syncfusion Team July 12, 2018 05:01 AM UTC

Hi Yukiko Imazu,  
 
We suspect that the issue raised due to return an  incorrect data to DropDownList. So, please do the below steps to find out the exact issue: 

Step 1: Put the debugger  before to return a data to view. 

<code> 

Partial Public Class ucPx
    Inherits UserControlClass 
 
      Public Function TitleCode_GetItems() As List(Of DAL.Data.Title) 
             Using db = New MemberData(Me.User)
                 Dim q = (From item In db.Titles
                     Select item).ToList 
                 Return q    // Please check this line if the data is returned or not.
             End Using 
         End Function 
 
End Class 




</code> 

Step 2: Check the data is binding correctly.  

Like as below screenshot: 

 

Step 3: If the data is not return correctly, then the issue is related to a sample side. 

We have prepared a sample based on your requirement. Please find the below sample link: 


If you still facing the issue, Please share the issue reproducing sample or make the shared sample as issue reproducible one.  

Regards, 
Karthikeyan V. 



YI Yukiko Imazu July 12, 2018 03:49 PM UTC

Hello Karthikeyan,

I checked the data is bind correctly.  The only difference is that it's wrapped by entitywrapper.  I attached screenshot.

I added code below.

   db.Configuration.ProxyCreationEnabled = False

Then it worked.  It worked without this code in original ASP.net dropdownlist, but I needed to add this code for binding ej:dropdownlist.

Anyway  Thank you!

Yukiko 


Attachment: entity_16c4d1cd.zip


KV Karthikeyan Viswanathan Syncfusion Team July 13, 2018 10:24 AM UTC

Hi Yukiko Imazu,  
 
  Thanks for your reply. 
 
In general, DB proxy overrides some virtual properties of the entity to insert hooks for performing actions automatically when the property is accessed.  Serializing non-proxy instances is considerably easier than serializing proxy instances. 
 
So, We suggest to use the non-proxy instances for override this issue. Otherwise, you can use asp:SqlDataSource directly insteadof using asp:ObjectDataSource. 
 
 
 
 
Regards,  
Karthikeyan V.  




YI Yukiko Imazu July 13, 2018 12:41 PM UTC

Hi Karthikeyan,

Thank you for your reply and help.
I appreciate it.

Best Regards,
Yukiko


PO Prince Oliver Syncfusion Team July 16, 2018 04:34 AM UTC

Hi Yukiko, 

Most Welcome. We are glad that your issue is resolved.  

Regards, 
Prince 


Loader.
Up arrow icon