Solved

Dropdown selected text and value property

Posted on 2008-06-17
9
317 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 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