Solved

Dropdown selected text and value property

Posted on 2008-06-17
9
299 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
 

Author Comment

by:PNKJ
ID: 21806784
obj_MergeDatatable = obj_Dataviewcommoditya .ToTable
            ddlcommodityList.DataSource = lobj_MergedDatatable
            ddlcommodityList.DataTextField = "Level4_text"
            ddlcommodityList.DataValueField = "AggrGrpID"
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now