Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Dropdown selected text and value property

Posted on 2008-06-17
9
310 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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