Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. problem with databinding dataviewmanager with dropdownlist at design time

problem with databinding dataviewmanager with dropdownlist at design time

Scheduled Pinned Locked Moved ASP.NET
helpdesigndata-structuresdebugging
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    padvit
    wrote on last edited by
    #1

    At run time need to determine the controls (dropdownlist) and set the values. at design i need to set datasource, datatext,datakey. the problem is these comboboxes receive data from different table but their column names are same and dont want to use different dataset and dataview. Iam using dataviewmanager. the code is as follows string sqlStr ="SELECT * FROM Categories;"; dAdapter = new OleDbDataAdapter(sqlStr,oleDbConnection1); dset = new DataSet(); dAdapter.TableMappings.Add("Table", "Categories"); dAdapter.Fill(dset); DataSet.DefaultViewManager property this.dviewmanager=dset.DefaultViewManager; this.DropDownList1.DataSource=this.dviewmanager; this.DropDownList1.DataTextField = "Categories.CategoryID"; this.Page.DataBind(); it is giving me following error DataBinder.Eval: 'System.Data.DataViewManagerListItemTypeDescriptor' does not contain a property with the name Categories.CategoryID. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: DataBinder.Eval: 'System.Data.DataViewManagerListItemTypeDescriptor' does not contain a property with the name Categories.CategoryID.

    M 1 Reply Last reply
    0
    • P padvit

      At run time need to determine the controls (dropdownlist) and set the values. at design i need to set datasource, datatext,datakey. the problem is these comboboxes receive data from different table but their column names are same and dont want to use different dataset and dataview. Iam using dataviewmanager. the code is as follows string sqlStr ="SELECT * FROM Categories;"; dAdapter = new OleDbDataAdapter(sqlStr,oleDbConnection1); dset = new DataSet(); dAdapter.TableMappings.Add("Table", "Categories"); dAdapter.Fill(dset); DataSet.DefaultViewManager property this.dviewmanager=dset.DefaultViewManager; this.DropDownList1.DataSource=this.dviewmanager; this.DropDownList1.DataTextField = "Categories.CategoryID"; this.Page.DataBind(); it is giving me following error DataBinder.Eval: 'System.Data.DataViewManagerListItemTypeDescriptor' does not contain a property with the name Categories.CategoryID. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: DataBinder.Eval: 'System.Data.DataViewManagerListItemTypeDescriptor' does not contain a property with the name Categories.CategoryID.

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, You may reconsider using the DataViewManager object as a datasource to bind to a dropdownlist control. Because, in the OnDataBinding event, a DataViewManagerListItemTypeDescriptor object is actually used to populate the item collection of the control, and basically this object does not have either the Categories.ProductID property or the CategoryID. In this case, the simple way is to use one the objects: dataset, datatable, and dataview to bind to the control:

      ...
      DropDownList1.DataSource = dset.Tables["Categories"];
      DropDownList1.DataTextField = "CategoryID";
      ...

      P 2 Replies Last reply
      0
      • M minhpc_bk

        Hi there, You may reconsider using the DataViewManager object as a datasource to bind to a dropdownlist control. Because, in the OnDataBinding event, a DataViewManagerListItemTypeDescriptor object is actually used to populate the item collection of the control, and basically this object does not have either the Categories.ProductID property or the CategoryID. In this case, the simple way is to use one the objects: dataset, datatable, and dataview to bind to the control:

        ...
        DropDownList1.DataSource = dset.Tables["Categories"];
        DropDownList1.DataTextField = "CategoryID";
        ...

        P Offline
        P Offline
        padvit
        wrote on last edited by
        #3

        This solution is not working iam mailing code snippet if you can help I have clearly told datasource,datatextfield to be set at design time The tables are of different name but they have same colums names at design level at run time Iam doing so string sqlStr ="SELECT * FROM Employees"; dAdapter = new OleDbDataAdapter(sqlStr,oleDbConnection1); dAdapter.Fill(dset,"Employees"); sqlStr ="SELECT * FROM Emp"; dAdapter.SelectCommand.CommandText = sqlStr; dAdapter.Fill(dset,"Emp"); this.Page.Databind(); I tried your code it didnt work

        M 1 Reply Last reply
        0
        • P padvit

          This solution is not working iam mailing code snippet if you can help I have clearly told datasource,datatextfield to be set at design time The tables are of different name but they have same colums names at design level at run time Iam doing so string sqlStr ="SELECT * FROM Employees"; dAdapter = new OleDbDataAdapter(sqlStr,oleDbConnection1); dAdapter.Fill(dset,"Employees"); sqlStr ="SELECT * FROM Emp"; dAdapter.SelectCommand.CommandText = sqlStr; dAdapter.Fill(dset,"Emp"); this.Page.Databind(); I tried your code it didnt work

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Hi there, + You should replace the '<' and '>' characters with '<' and '>' in your post, otherwise people cann't read it. + You don't need to set the DataTextField property at design time, you will do it at runtime. You are still able to use one dataset to fill up data for multilple dropdownlist controls at run time, the sample code looks like this:

          string sqlStr ="SELECT * FROM Employees";
          dAdapter = new OleDbDataAdapter(sqlStr,oleDbConnection1);
          dAdapter.Fill(dset,"Employees");
          sqlStr ="SELECT * FROM Emp";
          dAdapter.SelectCommand.CommandText = sqlStr;
          dAdapter.Fill(dset,"Emp");

          this.DropDownList1.DataMember = "Employees";
          this.DropDownList1.DataTextField = "EmployeeName";//I assume 'EmployeeName' is one of the columns of Employees.

          this.DropDownList3.DataMember = "Emp";
          this.DropDownList3.DataTextField = "EmpName";//I assume 'EmpName' is one of the columns of Emp.

          this.Page.Databind();

          Here, in the sample code the ListControl.DataMember property is used to specify which table will be bound to the control.

          1 Reply Last reply
          0
          • M minhpc_bk

            Hi there, You may reconsider using the DataViewManager object as a datasource to bind to a dropdownlist control. Because, in the OnDataBinding event, a DataViewManagerListItemTypeDescriptor object is actually used to populate the item collection of the control, and basically this object does not have either the Categories.ProductID property or the CategoryID. In this case, the simple way is to use one the objects: dataset, datatable, and dataview to bind to the control:

            ...
            DropDownList1.DataSource = dset.Tables["Categories"];
            DropDownList1.DataTextField = "CategoryID";
            ...

            P Offline
            P Offline
            padvit
            wrote on last edited by
            #5

            Hi Thank you very much for the reply As I have told already I have different tables with same columns name since these are being extracted from XML files. Second point The requirement as come in such a way where in I have to set these at design time not at run time. If these had to be set at run time my code would have worked very well

            M 1 Reply Last reply
            0
            • P padvit

              Hi Thank you very much for the reply As I have told already I have different tables with same columns name since these are being extracted from XML files. Second point The requirement as come in such a way where in I have to set these at design time not at run time. If these had to be set at run time my code would have worked very well

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              Perhaps, I misunderstood your requirement. Can we also try to set the DataMember property at design time like DataTextField and DataSource properties?

              ...DataMember="<%# dset.Tables[0].TableName%>"

              P 1 Reply Last reply
              0
              • M minhpc_bk

                Perhaps, I misunderstood your requirement. Can we also try to set the DataMember property at design time like DataTextField and DataSource properties?

                ...DataMember="<%# dset.Tables[0].TableName%>"

                P Offline
                P Offline
                padvit
                wrote on last edited by
                #7

                DataMember="<%# dset.Tables[0].TableName%>" This work fine with single control if there are more than one dropdownlists it gives error DataMember="<%# dset.Tables[0].TableName%>"//This works fine DataMember="<%# dset.Tables[1].TableName%>"//this gives error DataMember="<%# dset.Tables[2].TableName%>"//this gives error

                M 1 Reply Last reply
                0
                • P padvit

                  DataMember="<%# dset.Tables[0].TableName%>" This work fine with single control if there are more than one dropdownlists it gives error DataMember="<%# dset.Tables[0].TableName%>"//This works fine DataMember="<%# dset.Tables[1].TableName%>"//this gives error DataMember="<%# dset.Tables[2].TableName%>"//this gives error

                  M Offline
                  M Offline
                  minhpc_bk
                  wrote on last edited by
                  #8

                  + What does the error say? + I'm not sure if the markup on the page is the same as yours:

                  <asp:DropDownList id="DropDownList1" runat="server" DataSource="<%# dset %>"
                  DataMember="<%# dset.Tables[0].TableName%>" DataTextField="<%# dset.Tables[0].Columns[0].ColumnName%>">
                  </asp:DropDownList>
                  <asp:DropDownList id="Dropdownlist3" runat="server" DataSource="<%# dset %>"
                  DataMember="<%# dset.Tables[1].TableName%>" DataTextField="<%# dset.Tables[0].Columns[0].ColumnName%>" >
                  </asp:DropDownList>

                  In code-behind, I use the sample code in your post, and it's working. + You declare the dset dataset as typesafe or untypesafe?

                  P 1 Reply Last reply
                  0
                  • M minhpc_bk

                    + What does the error say? + I'm not sure if the markup on the page is the same as yours:

                    <asp:DropDownList id="DropDownList1" runat="server" DataSource="<%# dset %>"
                    DataMember="<%# dset.Tables[0].TableName%>" DataTextField="<%# dset.Tables[0].Columns[0].ColumnName%>">
                    </asp:DropDownList>
                    <asp:DropDownList id="Dropdownlist3" runat="server" DataSource="<%# dset %>"
                    DataMember="<%# dset.Tables[1].TableName%>" DataTextField="<%# dset.Tables[0].Columns[0].ColumnName%>" >
                    </asp:DropDownList>

                    In code-behind, I use the sample code in your post, and it's working. + You declare the dset dataset as typesafe or untypesafe?

                    P Offline
                    P Offline
                    padvit
                    wrote on last edited by
                    #9

                    Thanks you ver much I think the code is working fine, Iam still testing

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups