?
Solved

Dropdown selected text and value property

Posted on 2008-06-17
9
Medium Priority
?
333 Views
Last Modified: 2008-06-19
How can i set my datatext and datavalue field property. currently I am getting the error system.Data.DataRowView Does not contain a property with the name text.
code in aspx file for the drop down:
 <asp:DropDownList ID="ddlcommodityList" Visible ="false" runat="server" AutoPostBack="true"
                                        Width="150px" DataTextField="text" DataValueField="value" AppendDataBoundItems="true">
                                    </asp:DropDownList>
  I have function in code behind that populates the dropdown and is called twice and then dataview is merged.

  Dim lobj_UI As MasterUI = Nothing
       
        Dim obj_Dataviewcommoditya As DataView = Nothing
        Dim obj_Dataviewcommodityb As DataView = Nothing
        Dim obj_MergeDatatable As DataTable = Nothing
       
            obj_Dataviewcommoditya = lobj_UI.GetCommodityList("", "",ddlcommodityType.SelectedValue, "G")
            obj_Dataviewcommodityb = lobj_UI.GetCommodityList("", "", ddlcommodityType.SelectedValue, "T")

            obj_MergeDatatable = obj_Dataviewcommoditya.ToTable
           obj_MergeDatatable.Merge(obj_Dataviewcommodityb.ToTable)
            ddlcommodityList.DataSource = obj_MergeDatatable
            ddlcommodityList.DataBind()
     
MY merged dataview returns columns something like this ;
CommodityName, CatEgoryId, GroupId, AGGroupId, Level4_text, AggId, Level5_Text.

I want to set my ddlcommodityList.DataTextField = AGGroupId,
ddlcommodityList.datavalueField = Level4_text,   and then before i do the merge

It should be ddlcommodityList.DataTextField= AggId,
ddlcommodityList.datavalueField = Level5_Text.

so the same dropdown list but different datatext and datavalue property.
0
Comment
Question by:PNKJ
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 21806370
This is the problem: DataTextField="text" DataValueField="value"  in your DropDownList control.
In you datasource, there is no column called "text" or "value".

To accomplish your mission, you need first remove the above properties from your DDL control. Then before merge, you set those properties just you did in your post. After the merge, you can set those properties again with new values, but don't forget to rebind your DDL.
0
 

Author Comment

by:PNKJ
ID: 21806473
thanks but  I am gettign errors when I try to remove the columns that ar enot needed and then setting the text and value property. May be Iam not doing it right way
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21806486
What exactly did you do?
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:PNKJ
ID: 21806784
obj_MergeDatatable = obj_Dataviewcommoditya .ToTable
            ddlcommodityList.DataSource = lobj_MergedDatatable
            ddlcommodityList.DataTextField = "Level4_text"
            ddlcommodityList.DataValueField = "AggrGrpID"
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21806849
Did you remove DataTextField="text" DataValueField="value" from this?:
<asp:DropDownList ID="ddlcommodityList" Visible ="false" runat="server" AutoPostBack="true"
                                        Width="150px" DataTextField="text" DataValueField="value" AppendDataBoundItems="true">
                                    </asp:DropDownList>
0
 

Author Comment

by:PNKJ
ID: 21806964
Yes i did My drop doen ge filled up but I need to runthis function twice and merge the dataview
   obj_Dataviewcommodityb = lobj_UI.GetCommodityList("", "", ddlcommodityType.SelectedValue, "T")

            obj_MergeDatatable = obj_Dataviewcommoditya.ToTable
           obj_MergeDatatable.Merge(obj_Dataviewcommodityb.ToTable)
            ddlcommodityList.DataSource = obj_MergeDatatable
            ddlcommodityList.DataBind()
and this time the ddlcommodityList.DataTextField = "Level5_text"
            ddlcommodityList.DataValueField = "AggID"

and finally i need to bind the  dropdown
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 1500 total points
ID: 21807026
Not quite understand what you are trying to do...But a dropdownlist can only have one DataTextFiled and one DataValueField.
0
 

Author Comment

by:PNKJ
ID: 21807882
Yes  one dropdown can have only one DataTextFiled  and one DataValueField but in this case since my first dataview returns few commodities and when the function is called second time it get the rest of the commodities

MY merged dataview returns columns something like this ;
CommodityName, CatEgoryId, GroupId, AGGroupId, Level4_text, AggId, Level5_Text.

in my drop downlist i want to list all AGGroupId and AggId commodities and the datatext field for both the commodities are Level4_text  and Level5_Text. repectively. I want all the commodities combined liste din dropdown.
0
 

Author Comment

by:PNKJ
ID: 21807909
Is there any other way to achieve this like just selecting the AGGroupId and AggId from dataview as datatvaluefield and  combine Level4_text and Level5_Text. as datatext field.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question