?
Solved

Dropdown selected text and value property

Posted on 2008-06-17
9
Medium Priority
?
330 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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