Forms Data Controls :: Multiple Fields In DropDownList DataTextField And DataValueField?
Mar 2, 2010How to multiple fields in DropDownList DataTextField and DataValueField
[Code]....
[Code]....
How to multiple fields in DropDownList DataTextField and DataValueField
[Code]....
[Code]....
I'm currently working with a control that inherits from DropDownList (it has some extra functionality that isn't really relevant to this question, but it gives me a nice place to implement the extra stuff I'm gonig to discuss).
We're using data binding, with the DataTextField and DataValueField working absolutely fine. However, I find myself in need of a similar field that will control whether or not the item is enabled. (I've already overridden the RenderContents method of the control so it properly renders non-Enabled items, since DropDownList doesn't do this by default.)
Thus I'd like to know how to override the DropDownList's data binding so it acts exactly as normal, except a further field from each DataSource item is applied to each ListItem's Enabled property.
(NB: the field I'll be binding to isn't a straight boolean, and doesn't have an explicit/implicit cast to boolean, so I'll probably be "passing" it as a string.)
I have a dropdownlist for which I am loading data from excel. Excel has 2 columns Product and Email. Data in Product column is binding to DataTextField and Email column to DataValueField. The dropdown works fine when email is different for different product but when email has same value for different product then whatever I select, on postback the selected value changes to the first item of the same email value.
Below are the sample data in Excel to show the behavior of dropdown
Example 1. (Drop down works fine for this example)
Product Email
iPad prashanth364@gmail.com
iPhone 3G prashanth364@yahoo.co.in
iPhone4 prashanth364@in.com
Example 2. (In the example below, whatever I select (iPad or iPhone 3G or iPhone4) on post back the dropdown selected value will be iPad)
Product Email
iPad prashanth364@gmail.com
iPhone 3G prashanth364@gmail.com
iPhone4 prashanth364@gmail.com
Example 3. (In the example below, when I select iPad the dropdown works fine but when I select iPhone 3G or iPhone4 on post back the dropdown selected value will be iPhone 3G. Basically, on selecting iPhone4 here, on post back it shows iPhone 3G)
Product Email
iPad prashanth364@yahoo.co.in
iPhone 3G prashanth364@gmail.com
iPhone4 prashanth364@gmail.com
Below is the function where I am loaidng the data from excel to dropdown private void ExtractFromExcelInitial()
{
// Put user code to initialize the page here
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
string ExcelFilePath = Server.MapPath("~/ProductExcel") + "\ProductEmail.xls";
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + ExcelFilePath + ";" +
"Extended Properties=Excel 8.0;";
[Code].....
I have a list <Department> say Company.Departments with object Manager and ManagerId, ManagerName as property of Manager. I would like to fill the dropdownlist with managers as below
ddlManager.DataSource = Company.Departments;
ddlManager.DataTextField = "ManagerName";
ddlManager.DataValueField = "ManagerId";
Is there a way to specify the property of an object in DataTextField or I need to copy a Manager list for the DataSource?
I am trying to find out if there is an easier way to insert datavaluefield and datatextfied in a DDL.... I have two dropdownlist...the second ddl prepouplates based on the first one. All works now cos i have all my datavaluefield inserted. Now i was woundering if there is a way to caputure the datatextfied too so users can see it instead of seeing the ID alone. here is my code
<
ContentTemplate>
<asp:Button
ID="butAddEntity"
runat="server"
CausesValidation="False"
CommandName="Insert"
Text="Add"
OnClick="butAddEntity_Click"
/>
<asp:Button
ID="butCancel"
runat="server"
CommandName="Cancel"
Text="Return"
/>
<strong>Bank</strong>:<asp:DropDownList
ID="ddlBank"
runat="server"
AutoPostBack="True"
DataSourceID="BankCodes"
DataTextField="BankDirectory"
DataValueField="Bank_number">
</asp:DropDownList>
<strong>Account
Number:</strong>
<asp:DropDownList
ID="ddlAccount"
runat="server"
DataSourceID="RiskfactorDaily"
DataTextField="BalanceInfo"
DataValueField="NoteAccountNumber">
</asp:DropDownList>
</ContentTemplate>
And here is my datasoure and parameter
<
asp:SqlDataSource
ID="RelationShipMerge"
runat="server"
ConnectionString="<%$
ConnectionStrings:SenderoConnectionString1 %>"
ProviderName="<%$
ConnectionStrings:SenderoConnectionString1.ProviderName %>"
SelectCommand="SELECT
BankNumber, NoteAccountNumber, RecordID FROM RelationshipMerge WHERE (RecordID = @RecordID)"
InsertCommand="INSERT
INTO [Relationshipmerge] ([BankNumber], [NoteAccountNumber],[RecordID]) VALUES (@bank_number,@noteaccountnumber,@recordid)"
UpdateCommand="UPDATE
[Relationshipmerge] SET [BankNumber] = @BankNumber, [NoteAccountNumber] = @NoteAccountNumber WHERE [NoteAccountNumber] = @NoteAccountNumber"
DeleteCommand="DELETE
FROM RelationshipMerge WHERE (NoteAccountNumber=@NoteAccountNumber)"
OnSelecting="RelationShipMerge_Selecting">
<UpdateParameters>
<asp:Parameter
Name="BankNumber"
Type="Int32"
/>
<asp:Parameter
Name="NoteAccountNumber"
Type="String"
/>
<asp:Parameter
Name="recordid"
Type="Int32"
/>
</UpdateParameters>
<DeleteParameters>
<asp:Parameter
Name="NoteAccountNumber"
Type="string"
/>
<asp:Parameter
Name="RECORDID"
Type="int32"
/>
</DeleteParameters>
<InsertParameters>
<asp:Parameter
Name="bank_number"
Type="String"
/>
<asp:Parameter
Name="noteaccountnumber"
Type="String"
/>
<asp:ControlParameter
ControlID="GridView4"
Name="RecordID"
PropertyName="SelectedValue"
Type="Int32"
/>
</InsertParameters>
<SelectParameters>
<asp:ControlParameter
ControlID="GridView4"
Name="RecordID"
PropertyName="SelectedValue"
Type="Int32"
/>
</SelectParameters>
</asp:SqlDataSource>
I have used a webservice to populate a Rad Combo Box, when the page is loaded, I need the ability to display the DataTextField, based on the returned DataValueField item
View 1 RepliesI have 2 listboxes....
Listbox1 has
DataTextField="Category"
DataValueField="CategoryID"
(coming from Dropdownlist)
I want to move a Item (a Category) from listbox1 to listbox2...but how do I move this Category Plus the CategoryID to lisbox2 (CategoryID should not be visible but still be associated with Category in Listbox2)
So I want the newly added Categories to be visible in Listbox2 ..but their CategoryID's must be invisible...but still be associated with their Category....
and when I save these Categories from Listbox2 to the Database.....its should be the CategoryID's that should go into the Database.....not the actual Category
So to explain again in a different way
I want to Move a selected DataTextField & its DataValueField from Listbox1 to listbox2
then only the array of DataValueField must be saved to Database
I have a GridView with a DropDownList in it bound to the [Applicants] table in SQL Server 2005.
The DropDownList Items Text and Value come from SqlDataSource3, "SELECT VoucherType, VoucherNumber FROM [Vouchers]"
I need to send the DDLs selected Text to [Applicants].[VoucherTypeIssued] and the Value to [Applicants]. VoucherNumber]
I already have a "dlVoucherTypeIssued_SelectedIndexChanged" event in the code behind to put "Voucher Issued" into [dbo].[Vouchers].[VoucherStatus]. I'm having trouble getting all three values written to the database at the same time.
in dropdownlist show the all PatientName and save the PatientID . how to show the PatientName in DataGrid.
PatientID, PatientName are Foreign Keys. In DataBase on Save the the PatientID my requiredment is PatientName show in DataGrid based on PatientID.
I have a dataset which I am binding to a listbox. However, I want to combine two of the fields to make up the DataTextField. Is this possible, or am I going to have to loop through the Data Rows?
lstAddressDropdown.DataSource = dsAddress;
lstAddressDropdown.DataTextField = "StreetAddress" + "Place";
lstAddressDropdown.DataBind();
lstAddressDropdown.Items.Insert(0, new ListItem("Please select"));
It's worth noting that the dataset comes back from a web service so I can't change any stored procedure to combine the columns there.
How to select multiple fields from a dropdownlist..
View 6 Replies[Code]....
I've used DataValueField = "ID".
How do I get an ID in DropDownList?
So I have a major issue and cannot find any solution online to solve it excepting one that is singlistviews. But i am also encounting some probs with listviews since i am not sure of to use it.Anyways so my major issue is that I have drop down lists that are being populated by a sqldatasource. Users are filling out a form selecting values in the drop down list which is fine, the prob exists with editing a record. I have the dataValuefield to be the Id of the data and the selected item in the dropdownlist id is being stored in a database. So I have the data in the database that is the Id of the selected item however I cant use the dropdownlist1.selectValue ='idNo' since that only works with listitems.
How can i access the dynamic rows in a dropdownlist that is being populated by a sqldatasource and set the selected item to a particular item?Any insight is greatly welcome. Even how to use listviews
I would rather not magic string my DataTextField/Values on the dropdownlist after setting up the source as a List collection of objects.
I was thinking I could use the DataSource properties but it doesn't seem to like the couple of ways I tried.
WORKS BUT NOT IDEAL
//set the datasource to the returned List<Cart>
this.cartDdl.DataSource = CartManager.Load(WebProfile.Current.UserName);
//set the DataValueField to the Cart.ID property
this.cartDdl.DataValueField = "ID";//would rather use the obj property Cart.ID
//set the DataTextField to the Cart.Description property
this.cartDdl.DataTextField = "Description";//would rather use the obj property Cart.Description
//Bind the ddl to the datasource
this.cartDdl.DataBind();
HOW I WOULD THINK IT COULD WORK this.cartDdl.DataValueField = ((Cart)this.cartDdl.DataSourceObject).ID; this.cartDdl.DataTextField = ((Cart)this.cartDdl.DataSourceObject).Description;
In Asp.Net 3.5, it is possible that the DataValueField is a IList ?
myddl.DataValueField = "ListOfId"
where ListOfId as a IList in my DataSource
Can I put multiple fields value into the text properties of a link button? My below codes doesn't work. I would like to display "000001-1", "000001" being the job_id and "1" being the job_seq and separated by a dash.
[Code]....
Is there a way to display several records in the datatextfield in a asp dropdownlist? I know the fix when populating the dropdownlist from a datagrid was to edit your SQL query but the values I am receiving are sent via an XML string. The idea would be to display a name, price, and date in the dropdown text. Currently I am getting the following error: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'MonetaryValueServiceType' While using UPSDropDown.DataTextField = "MonetaryValue" & "ServiceType" Is there a work around to do this? The only other option is to use radio buttons (which are also a nightmare).
View 1 RepliesI have a State class defined like this:
Public Class State
Public Property StateId As Integer
Public Property Name As Dictionary(Of Integer, String)
End Class
Name(x) contains the state name in different languages. I get a collection of State from the method StateManager.GetAllStates() and I want to bind this collection to a DropDownList. The problem is that I can't find how to set the DataTextField property to let's say stateList.Name(1) which is the english name of my state.
Dim stateList As StateCollection = StateManager.GetAllStates()
Me.DataSource = stateList
Me.DataValueField = "StateId"
Me.DataTextField = "Name(1).Value" <-- Problem here
Me.DataBind()
I have 2 dropdownlist - State and City. I want to fill city drop down list on selectedIndexChanged event of state drop down list. I fill the State ddl ( DataTextField = "Locationname" & DataValueField = "Locationid" ) using linq and when i changed state I didn't get "Locationid" and I got error - " conversion from string "Locationid" to type "Double" is not valid" .
following are the code
[Code]....
I am not sure if my subject is phrased properly but here is what I am getting problems with.I have a detailsview which had about 3 dropdownlist (ddl) on it. The DDL's works fine when I insert a new record or I try to edit an existing record.But when I just want to view the data in the detailsview it displays the primary keys (DataValueFields) instead of the associated DataTextField Value.
View 6 Replieshow to show the dropdownlist datatextfield selected text in the DataGrid
View 2 RepliesI am not able to find the projects related to working with excel sheets by using ClosedXML to refer. I have an excel book which contains two sheets.
In sheet 01: In column A: In B: In C:
Student name01 Student's phone number blabla
Student name02 Student's phone number blabla
Student name03 Student's phone number blabla
In sheet 02: In column A: In B: In C:
course name01 computerscience blabla
course name02 dhfsthshbstgs blabla
course name03 garsfghsefrgs blabla
now, I would like to see in two comboboxes (all the words/text presented in the column A) from two sheets, the student name and course name and then I want select any student name and course name of my choice. Afterwards, when I click on a button, my program should display the students phone number and the course name (from column B from both sheets) and related things present in the Column C D E.. of the selected things in combobox in a label or a in a textbox.
PS: I solved the following problem: I can select student name in one combobox and print the the corresponding data from the only one column B (but I worked only with one sheet). It is bit complicated for me to continue with two sheets.
how to put three rows of one table data in gridview one coloumn
how to add text1,text2,text3 rows data in upper as i write but the proper code
<asp:BoundField ItemStyle-Width = "150px" DataField = "LT_SHOWNAMETEXT1" HeaderText = "SHOW NAME"/>
<asp:BoundField ItemStyle-Width = "150px" DataField = "LT_TEXTTYPE" HeaderText = "TEXT TYPE"/>
<asp:BoundField ItemStyle-Width = "150px" DataField = "text1,text2,tex3 " HeaderText = "TEXT"/>
[Code].....
I have the above html for gridview instead of first name, middle name, last name
I need one single column name
<asp:GridView ID="gridview1" runat="server" Width="450px" DataKeyNames="id" OnRowCommand="OnRowCommand"
AllowSorting="True" Height="170px" AutoGenerateColumns="False" AllowPaging="True"
OnPageIndexChanging="gridview1_PageIndexChanging">
[Code] ....
I have a method in my button code to run the query, it returns a value and save it to a Session variable to be used later, this code works.Dim connString As String = ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionStringUsing myConnection As New SqlConnection(connString)
Const sql As String = "SELECT Rate1 FROM Rates WHERE (LayerID = '01')"
Dim myCommand As New SqlCommand(sql, myConnection)
myConnection.Open()
[code]...