Web Forms :: Assign A Property Of An Object As DataTextField And DataValueField?
Feb 5, 2010
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?
View 2 Replies
Similar Messages:
Jun 28, 2010
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>
View 4 Replies
Mar 2, 2010
How to multiple fields in DropDownList DataTextField and DataValueField
[Code]....
[Code]....
View 2 Replies
Jun 1, 2010
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.)
View 1 Replies
Nov 23, 2010
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 Replies
Mar 24, 2011
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].....
View 1 Replies
Jul 9, 2010
I 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
View 3 Replies
Aug 13, 2010
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;
View 2 Replies
Jan 30, 2011
i get a list of objects from the Entity Framework data context.
var list = context.EntityA;
the EntityA is the main object (contains the primary key), but has a navigation property called "EntityALanguages", which contains language specific properties.
now i want to bind the list to a dropdownlist and need so set DataValueField and DataTextField properties from the dropdownlist.
how can i set the DataTextField to a property of a navigation property, something like:
this.ddl.DataValueField = "GUID";
this.ddl.DataTextField = "EntityALanguages.ShortDescription";
View 1 Replies
Oct 29, 2010
I 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()
View 2 Replies
May 24, 2010
I have a class (SearchClass) in which i have Origin property which is a "Address" datatype. I want to use the "Search" class in my Search.aspx. I want to bind the City field data to a CheckBoxList, but i could not do so? If it is a straight property of Search class i could do so, but if it is a property then i could not. "I am getting error "City" is not a valid DataTextField of something like that. The point is it is not recongnised. I even tried to inherit the Address class from Search.cs class, but i just see blank data. Now i am trying to a different thing. i.e. Inherit the Address in Search.cs class and while pouplating the Search Results in to a List object i am also planning to set the data of City too, along with populating the whole Address objects and try to use it in my binding. Is there any other way to do this (i mean more efficiently)?
SearchClass.cs:-
[Code]....
View 3 Replies
May 3, 2010
Traditionally with an Object Data Source, the wired up class will have its public properties available for binding (i.e. Gridview columns, etc.) which works well. But what if one of my wired up business objects has a property that is an object itself; can I drill down to a property on that object property and still use it?
So in additiona to the traditional:MyBusniessObject.OrderID...I want to use:MyBusniessObject.Customer.NameID
Your 1st response might be to just wire up the 'Customer' class, but I need properties both on 'MyBusinessObject'and 'Customer'. I do not think this can be done, as the ODS will not display properties on an object instance property. I have tried manually typing in the drilled down value as well, but that wasn't a success either.
View 4 Replies
Sep 10, 2010
I have a masterpage that contains all the javascript and inside the content control, there is a link that calls a javascript function and I want to pass the id once it's rendered differently by the server.
<asp:TextBox ID="txtstart" runat="server" Width="20%"></asp:TextBox>
<a title="Pick Date from Calendar" onclick="calendarPicker('<% txtstart.ClientId %>');" href="javascript:void(0);">
However, I keep getting this error:
Property access must assign to the property or use its value.
How would I be able to accomplish this?
View 1 Replies
Apr 1, 2011
Here's the code below:
[Code]....
The application that I am currently modifying is using an xsd file and the stored procedure has parameters which are passed.
View 2 Replies
Nov 19, 2010
I have a type that is derived from an Entity generated by the Entity Framework 3. How do I assign one Customer's Order property to the Derived Customer's Order property?
derivedCustomer.Orders = customer.Orders
I'm not actually trying to swap orders; this is just an example of what I am trying to achieve. Has anyone done tried this and succeed?
View 1 Replies
Sep 13, 2010
I have a custom class downloaded from internet. In this class, there is a properties where by the value can be either 0, 1 or 2 only and I MUST assign it during run-time. But some how, this assignment only work using VB, and not C#.
[Code]....
In C#, it the compiler said "missing cast or conversion...". But in VB, it works perfectly.
View 12 Replies
Apr 22, 2010
I have a ASP.Net page that has a gridview control. This gridView control has a checkbox controls. I would like to assign a boolean value from a database field to the Checked property- Checked='<%# Bind("RESULTS") %>'.
When page loads,I get error - Specified cast is invalid!
The code is as follows...
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="dsResults"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" OnRowUpdated="GridView1_RowUpdated">
<Columns>
<asp:TemplateField HeaderText="COMPLIANT" SortExpression="RESULTS">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("RESULTS") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("RESULTS") %>'
Enabled="False" />
</ItemTemplate>
</asp:TemplateField>
Note: If a constant value is passed at design time it works fine. But i want to assign the value at runtime using Bind.
Environment details: VS 2008, ASP.NET 2.0 and .Net Framework 3.0 & C# language.
I tried returning values like 0s and 1s, Ys and Ns and True and False from a database field. But i still get the above mentioned error.
I tried retreving the value in OnRowDataBound event using Eval, since Bind is not available in code behind. But it would make the field readonly and i cannot edit and update the Results field.
Even though there is a value returned by the query why does the Checkbox does not assign the value using <%# Bind("Results") %> to Checked property instead throws error - Specified cast is invalid.
how i can edit and update Checkbox.
where did the Bind method of ASP.Net 1.x is moved? How can i use Bind in code behind of ASP.Net 2.0?When i type DataBinder the intellisense shows Eval and other stuff but i don't see Bind that would solve the problem of two- way binding.
View 16 Replies
Nov 10, 2010
foreach (DataGridViewRow item in dataGridView1.Rows)
{
if (Convert.ToBoolean( item.Cells[0].Value) == true)
{
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
**class oclass=new class();
oclass.property = item.Cells[col.Name].Value.ToString();
Collection.add(oclass);**
}
}
}
In the above syntax,i want to fill class property dynamically.I also add my class in collection.Is it possible in C#,fill class property dynamically?My grid contain more than one column.My grid's column name are same as class property name.I want to do the bellow thing:
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
**class oclass=new class();
oclass.col.Name= item.Cells[col.Name].Value.ToString();
Collection.add(oclass);**
}
View 2 Replies
Mar 19, 2010
How to assign MaxLength Property to BoundField column in DetailsView COntrol without Converting into TemplateField.
View 3 Replies
Jan 3, 2011
I would like to dynamically load a user control and assign one of its public properties OnLoad...
I'm doing the following from a parent user control to dynamically load the child user control...
UserControl uc = (UserControl)Page.LoadControl("~/Controls/MyUserControl.ascx");
What else do I need to do to pass a value so its public property is set OnLoad?
View 3 Replies
Feb 23, 2010
I have a GridView that displays records based on a SQLDataSource, which gets it's data from a very simple stored procedure. I want to use stored procedures to update & delete records in the GridView, which I have done in the past.
Our organization requires that the names of the parameters within our stored procedure start with "@p" to differentiate between passed parameters and internal variables. This is causing me my issue. If I change the stored procedure code to reference the fields without the "p", everything works properly. This is because the SQLDataSource parameters use the default ParameterPrefix of "@" and correctly references the stored procedure parameters. Here is the relevant code:
[Code]....
I found a MS article describing how to override the default ParameterPrefix, but I am unable to implement it. I can add their example code, but how do I "assign" this property to my GridView?
View 2 Replies
Nov 11, 2010
I've got a SQL Server database with a table in it, which lists the file names of images. It's my intention to assign the ImageUrl of an Image control on the page, from the data in the table. I've placed a SQLDataSource control on the page, and then tried putting a FormView control there, and an Image control within that. But I don't see how I can assign the value to the ImageUrl property via data binding.
View 3 Replies
Aug 31, 2010
I have a control and list of variables and I want in the control property to be assigned to the variable value directly in the page not from the back code, something like this
My global variables
public string Banana = "banana_pie";
public string Apple = "apple_pie";
in my custom control instead of:
<uc:LoadPie id="pieBanana" type="banana_pie" />
To this
<uc:LoadPie id="pieBanana" type="<%=Banana %>" />
so is there a way or just assign the property in page back code.
View 3 Replies
Aug 10, 2010
have a table releases with release id and release name and the child table as Sprint. But I am getting an exception while the page loads saying the property or object name release id couldnt be found
public
partial
class
Default2 : System.Web.UI.Page
[Code]....
View 4 Replies
Aug 30, 2010
I have a parent & child table.
Parent - User
UserID
UserName
Status
1
Shallin [code]...
I also have parent & child object class.I would like to use 1 C# function and 1 SP to handle the retrieve portion but I have 1 problem.I'm not sure how to assign the value from Reader to the object.I do something like this but I only get 1 country which is the last country.
if (dr.HasRows)
{
while (dr.Read()) [code]....
how to handle this Parent/ child object with only 1 function and 1 SP?
View 3 Replies