C# - DropDownList.DataValueField In A IList?
May 13, 2010In Asp.Net 3.5, it is possible that the DataValueField is a IList ?
myddl.DataValueField = "ListOfId"
where ListOfId as a IList in my DataSource
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
[Code]....
I've used DataValueField = "ID".
How do I get an ID in DropDownList?
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].....
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
How to multiple fields in DropDownList DataTextField and DataValueField
[Code]....
[Code]....
i m developing a Web Application with C# (with NHibernate)
want to bind the IList with the gridview ...for that i hav to convert IList to datatable .
IMPORTANTLY my Database table that i want to pull(through Nhibernate) contains 3 foreign keys now wat to do convert ?
I have recently started to use Nhibernate and i am quite happy with it until i needed to BIND to ASP.NET controls. I was having major issues binding a gridview to a collection of Products (IList). In the end i was forced to right a small routine to convert my IList to a DataTable. Once it was in datatable it worked flawlessy.
Now has come the time to bind a standard Dropdownbox to 1 field of a collection (IList) of Products but it appears i am having issues again.So this has brought me to the conclusion that i must be doing something wrong?I can't believe that it isn't possible to BIND ASP.NET controls to a collection (IList) of a class (in my case products) that is returned from NHibernate.I would really appreciate any feedback anyone has on the situation... I am at a loss
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 a Listbox
dimension.DataSource = provider.DimensionList;
dimension.DataBind();
I want the value to be the ID of these elements
dimension.DataSource = provider.DimensionList;
dimension.DataValueField = "ID";
dimension.DataBind();
But I don't want the text to change to the ID, I want that the dimension.DataTextField gets the object.ToString().
[Code]....
Can we implement through LINQ ?
I have a DataTable that was built from dynamically created SQL, so I do not know the number of columns in the datatable.
How can I convert this datatable into an IList?
EDIT: I am then going to use this to send to a Telerik Grid on the page.
I have a table say, Student.
I have a class 'Student'.
I want to populate IList<Student> with objects of Student class from Student table in database.
Is it possible to implement this?
If yes then how to implement this.
I am trying to create a generic list of objects using reflection. The below code throws an error Cannot create an instance of an interface. . I could change the IList to List and it works fine, but I was wondering if there is way to get this working with an IList.
var name = typeof (IList<T>).AssemblyQualifiedName;
Type type = Type.GetType(name);
var list = Activator.CreateInstance(type);
User's need to "download" an excel sheet with data.
However this sheet need to be created on the fly (user's can check of which data they want exported).
From the user's point of view, it will just be a link "Download Now".
From coding point of view I will have an IList<MyClass> where MyClass say got members like EntryId, FirstName, LastName etc.
I do not want all fields to be dropped into the sheet (so I will need control over that in my code)
This sounds like what I'm after (since I'll always only have one sheet)
Create an HTML document and save it with a .xls extension - Excel will open it and treat it like a native Excel file. This method is very simple and, of course, free - however, it won't allow you to have more than one worksheet in the Excel workbook...
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'm using radcombobox and radgrid.Here i want to display ward_no but store ward_id in database.But in my code ward_id field not store, ward_no is store. What is the problem?
My code is......
<telerik:RadComboBox ID="ddWardNo" runat="server" DataSource='<%# ddWardBind() %>' DataTextField="ward_no" DataValueField="ward_id" Skin="Vista" Width="205px" >
</telerik:RadComboBox>
I am using a combobox.
I'm retrieving the data from database to fill the combobox. The name of the combobox is kategorilist. I want to set a string value to datavaluefield of the combobox. Also I'm using datalist with paging in this page. Datalist is binding with the selected value of the combox everytime.
Like this;
li.Value = "urunlist.aspx?ktid=" + dr["KategoriID"] + "&Sinif=" + sinifsa.ToString();
But it doesn't work. It worked with html <select> tag but ajax combobox doesn't accept this value.
Here is my code:
private void KategoriAdlariniGetir(int sinifsa)
{
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection(cnnstr);
[Code]....
What do I use to set the dataValueField of the Select List when I'm using a list of strings. I want to be able to set the value of the option in the select. If i have:
List<string> list = new List<string>();
list.Add("apple");
list.Add("orange");
and I want my html to be:
<select>
<option value="apple">apple</option>
<option value="orange">orange</option>
</select>
I am trying to bind the panel bar with the IList. I have the follwing code in my class libarry
[Code]....
I need to bind the panel bar with getmenuItems. In the above code DataReviw, Score Rep, Something else, section 2 and sample are the parent node of the panel bar and Test1,
/rRepScore/Index,
/something/something,
"Test3",
"/repScoring/Selectreps"
are the childeren of the panel bar and they are the link to another web page.
how to populate a ilist object with data frm a sql table in code behind
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'm using MVC 2.0 in an ASP.NET application using NHibernate. I have a working View, Controller and data access layer using NHibernate that is able to display and save an entity with a relationship to another mapped entity: Person -- > Location It's using the HTML helper HTML.DropDownListFor() to display a list of all Locations. The user is able to select one of the Locations from the list, and press save. The default model binder correctly sets the value of the Location on the Person entity being saved. This location is an nhibernate mapped entity, and is instantiated and has the id value that was selected in the dropdown list. Obviously, since the dropdown list that holds locations only has the ids of the locations, the rest of the values for the location are null. This is OK. I am only trying to save the Person with a reference to an existing location.
So, here comes the complication. We have a need to change the relationship between the two entities. Now the Person can have a reference to many locations. Person.Locations will be an IList My question is, how do you get the default model binder to take selections from a multiselect dropdown and populate an IList. I've managed to save collections of entities in the past using the syntax [index].PropertyName as explaing by Phil Haacked .... [URL]
The issue here is that I have only a dropdown list, and it will post back to the modelbinder a repeating key with different values:
Person.Location.Id: 2
Person.Location.Id: 4
Person.Location.Id: 5
This, unfortunately, doesn't work. the Location list keeps coming back Null. Our UI guy is using a slick JQuery pluggin to display the items in the select list, so I'd rather not have to use a different UI.
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?
Okay, so I have a Generic IList of custom objects that I want to use as a datasource for a repeater.
[Code]....
In the WebForm inside the repeater, I place this code:
[Code]....
when I try to run it, I get the error "Unable to cast object of type 'System.Collections.Generic.List`1[MyCustomObject]' to type'MyCustomObject'. ". Which makes sense, really.
What's the best way round this? Is there any way I can get the direct cast working? I'm loath to have to create a custom list item that implements IBinding or something and bind that directly, as that'll mean a lot of legacy changes which may create further bugs. Or is there a better way?