C# - Bind The Values Without Duplicates From Database Into Dropdown Using LINQ?

Apr 2, 2011

I have a small issue binding the values into a dropdown using LINQ in ASP.NET code-behind.

var clientquer = from i in Entity.New_Bank select i;
//var q = (from s in names
// select s).Distinct();
// var getlendername = (from db in mortgageentity.New_Lender group db by db.Bank_Name into t select t.Key).ToList();
if (clientquer.Count() > 0)
{
ddlbankname.DataSource = clientquer.ToList();
ddlbankname.DataValueField = "Bank_ID2";
ddlbankname.DataTextField = "Bank_Name";
ddlbankname.DataBind();
}

It is binding with duplicate values, but I don't want bind duplicate values. I'm trying to solve this by using a group by clause, but it is not working.

View 2 Replies


Similar Messages:

MVC :: Bind An Enum Values To A Dropdown List

Apr 26, 2010

I would like someone to explain how I can pass a drop down list from the presentation layer to the controller using the Model View Controller Design Pattern from Microsoft in order to bind enum values to it?

View 2 Replies

Bind Datafield To Dropdown List With Hard Coded Values?

Jan 19, 2010

I have a dropdown list with hard coded values:

<asp:ListItem Text="One Day Shoots" Value="1" />
<asp:ListItem Text="Multi-day Shoots" Value="2" />

I want to use this to insert and edit values from a db. For example when adding a record the user selects 'One Day Shoots' and 1 gets inserted into the database. Then if the user goes to edit the page since the value in the db is 1 then the 'One Day Shoots' is selected.

One way I considered accomplishing this was by using a hidden feild - when the user selects something in the dropdown list the field is updated with the value, then when the user actually adds the record the value in the feild is submitted. I'm pretty sure this would work but is there a better way?

View 3 Replies

How To Bind The Data From Database To The Dropdown

Sep 30, 2010

Suppose in .aspx page their is dropdown in which i want to bind two coloumn in that dropdown.for example :-

in database their two column of First_name ,Last_name .I want these two columns value come in a single dropdown using C#.

View 2 Replies

Bind Textbox To Database Record Via Dropdown Selection

Feb 11, 2014

I am trying to bind a record to a textbox using a Dropdown selected index change. I get the error.

Conversion failed when converting the nvarchar value 'DrFirstName DrLastName,Ph.D.' to data type int. is it because I concatenate the name and prefix of the DR into the Dropdown list like this,

Code:
SELECT ID,EmailAddress, DrName + ',' + PreFix AS DrName FROM DrNames

Here is the dropdownlist code that I want to populate the textbox with the emailaddress in the table associated with Dr name and ID.

Code:
Private Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim dt As New DataTable()
If DropDownList1.SelectedItem.Text = "OTHER,..." Then
txtRx1.Visible = True
DropDownList1.Visible = False
End If

[Code] .....

View 1 Replies

Bind Dropdown To Local (browser) Database With HTML5/jQuery?

Oct 11, 2010

So I know how to store and retrieve data in a local database (Chrome). My function to retrieve data is

function SelectHandler(transaction, results) {
for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);

[code]...

View 1 Replies

C# - How To Populate Dropdown With A Database Result In Mvc Linq EF

Mar 16, 2011

Here is my Controller:

public class MatchManagerController : Controller
{
//
// GET: /MatchManager/
public ActionResult Index()
{
return View();
}
public ActionResult CreateMatch()
{
return View();
}
}

Here is my View:

@model MatchGaming.Models.MatchModel
@{
ViewBag.Title = "CreateMatch";
}
CreateMatch
@using (Html.BeginForm()) {
@Html.ValidationSummary(true).....

I want my MatchTypeId to be a drop down that populates from my table MatchTypes.

View 1 Replies

Forms Data Controls :: Taking Care Of Duplicates In A Dropdown List?

Mar 22, 2011

I have query that returns a line that looks like this belowA NEWYORK PROGRAM AA NEWYORK PROGRAM Bnow, the NEWYORK is inputted into a dropdownlist and the program A and program B is inputted into a dropdownlist as wellI am using utility.ControlTools.SetListControl for my dropdownlist. I would like a situation where my dropdownlist only contains one NEWYORK instead of two and my dropdownlist for programs to contain Program A and program B. Can this be done.

View 2 Replies

Forms Data Controls :: Dropdown List Bind With Database Inside Gridview

May 30, 2010

I have created an asp.net customizable gridview where user will be able to add and delete data. Now I face some proplem with this gridview. now I want to add a dropdown list (which is dynamically bind with database) inside the grid. I created code and it bind well. when the page is post back previous selected dropdown list value lose and set to selectedIndex=0; For this reason I used if(!page.Ispostback) and put the dropdown binding code inside this. Here I faced a problem. The problem is when I want to add data inside grid the dropdownlist missin bind. How can I overcome this problem? For your kind observation I given entire code below:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None"
onrowdeleting="GridView1_RowDeleting"
onrowdatabound="GridView1_RowDataBound">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:TemplateField HeaderText="SL">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("RowNumber") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("RowNumber") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Material">
<ItemTemplate>
<asp:DropDownList ID="drpMaterial" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtQuantity" ErrorMessage="Required Field Missing">*</asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>...............................

View 8 Replies

How To Bind Values In Combobox From Database

Aug 1, 2010

how to bind values in combobox from database in that combobox my first value should be display as <----select----->, but i have no such values in my database.

View 5 Replies

Bind Database Values To A Calendar?

Mar 26, 2010

how to bind database values to a calendar. What i am trying to do is the following. i've got a stored procedure in an sql server database which checks if a backup is done correctly or not with some other information in different collumns. There is one column with the end date and one column with the status of the backup.

what i am trying to do is to bind the calendar so that when the backup finished on lets say 27 th of march and it ended correctly or not i want to see in my calendar on the 27th of march the status information. how is the best way to approach this.

View 2 Replies

C# - Get DropDown Values From Database Table?

Mar 30, 2011

I have a ASP:DropDown list which is populated by the following:

public void Fill1()
{
string connectionString = WebConfigurationManager.ConnectionStrings["CRM2Sage"].ConnectionString;
using (SqlConnection _con = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Products", _con))
{

[Code]....

View 1 Replies

Dropdown List Won't Populate Values From Database?

Oct 4, 2010

I'm stuck with a problem to populate a DropDownList control with values from the database using item field template in read only mode. since I'm new to ASP.NET. Below is the code and the error I'm getting:

'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

The code for this is :

<asp:SqlDataSource ID="categoriesDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand ="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId)">
<SelectParameters>

[Code]....

View 1 Replies

Web Forms :: Record DropDown List Values As ID To The Database

Nov 11, 2010

i am using a list view to view, insert, update and delete my data for the admin page this admin page made for the news and we have categories for that so i need to use a drop down list for these categories and when the admin choose on of these categories records its value as an ID to the database.

[Code]....

View 8 Replies

Dropdown List Wont Populate Values From Sql Database?

Oct 6, 2010

I have an application as: SelectCommand="SELECT [CategoryID], [Name], [UserId] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]">

</asp:SqlDataSource>
Pick a category: <asp:DropDownList ID="categories" runat="server" AutoPostBack="True"
DataSourceID="categoriesDataSource" DataTextField="Name" [code]...

When i take away the <SelectParameters>

<asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" />
</SelectParameters> and ([UserId] = @UserId), the dropdown list control will populate values from the database but when i live those 2, it won't populate any value from the database. When i remove the <asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" />
</SelectParameters>,and live ([UserId] = @UserId), i get the error : Must declare the scalar variable "@UserId".

View 1 Replies

Web Forms :: Load The QuoteNumber Database Column Values Into Dropdown?

Mar 2, 2010

How can i load the QuoteNumber database column values into dropdown list which is autogenerated column.I am able to generate the QuoteNumber value and same inserting into database simultaniously all the Quotenumber values should load into dropdown, these two should happen in one click button event.My QuoteNumber dropdown name is "DDQuote" Code for generating Quotenumer and same inserting into database.

Protected Sub btnAQ_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAQ.Click
Console.WriteLine(updateRecord("insert into quotes (PartNumber) values ('" + txtPart.Text + "')"))
retriveDataToDataGrid()
End Sub
Function updateRecord(ByVal query As String) As Integer
Try
Dim connectionString As String = "Database=fabdb;" & "Data Source=localhost;" & "User Id=root;Password=pacvision"
Dim rowsEffected As Integer = 0
Dim connection As New MySqlConnection(connectionString)
Dim cmd As New MySqlCommand(query, connection)
connection.Open()
rowsEffected = cmd.ExecuteNonQuery()
connection.Close()
Return rowsEffected
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Function

View 5 Replies

Forms Data Controls :: Dropdown Won't Populate Values From Sql Database

Oct 6, 2010

Ive been strugglng with this one problem for a while now. I have an application as: SelectCommand="SELECT [CategoryID], [Name], [UserId] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]">
<SelectParameters>
<asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" />
</SelectParameters> [code]....

the dropdown list control will populate values from the database but when i live those 2, it won't populate any value from the database. When i remove only the
<asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" />
</SelectParameters>
and live ([UserId] = @UserId), i get the error : Must declare the scalar variable "@UserId".

View 2 Replies

Forms Data Controls :: Load Values From Database To Dropdown Before AddQuotenumber Button?

Mar 11, 2010

I have Dropdown for Quotenumber(auto increment ).i have created a function to retreive the data from database.data loading into dropdown. when i click on Addquotenumer button the new quotenumber generated and same loading into dropdown but 2 set of Quotenumbers are displaying rather than singleset, i debudded the code the reason was i have called this function twice one is form load and another one in AddQuotenumber button event,both should manadetory as per my requirement. how can un load this dropdown before AddQuotenumber button

Function to retreive data to dropdown
Public Sub retriveDataToDropDown()
Try
Dim connectionString As String = "Database=fabdb;" & "Data Source=localhost;" & "User Id=root;Password=pacvision"
Dim query As String = "SELECT QuoteNumber FROM quotes"
Dim connection As New MySqlConnection(connectionString)
Dim da As New MySqlDataAdapter(query, connection)
Dim ds As New DataSet()
If da.Fill(ds) Then
DDQuote.DataSource = ds.Tables(0)
DDQuote.DataTextField = "QuoteNumber"
DDQuote.DataBind()
'DDQuote.Items.Insert(0, New ListItem("Select", "Default value"))
End If
connection.Close()
Catch ex As Exception
'Console.WriteLine(ex.Message)
End Try
End Sub
AddquoteNumber button code
Protected Sub btnAQ_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAQ.Click
Dim connectionString As String = "Database=fabdb;" & "Data Source=localhost;" & "User Id=root;Password=pacvision"
Dim rowsEffected As Integer = 0
Dim Query As String = ""
Dim connection As New MySqlConnection(connectionString)
'Dim cmd As New MySqlCommand(Query, connection)
connection.Open()
Query = "insert into Quotes(query follows...................)
retriveDataToDropDown()
retriveDataToDataGrid()
connection.Close()
End Sub

View 8 Replies

ADO.NET :: Linq And Webservices / Create A Webservice Method Using LINQ Technology And To Populate A Dropdown In a Form?

Oct 6, 2010

I am struggling to create a webservice method using LINQ technology and to populate a dropdown in a form. Here is the Webservice code.

[WebMethod]

public
string[] GetAllCountries()
{
LinqClassesDataContext db =
new
LinqClassesDataContext();
var q =
from c
in db.ListContinents()select
c;
return q.ToList() ;
}

And here is the form code behind

protectedvoid
Page_Load(object sender,
EventArgs e)
{
WSClass WS =
new
WSClass();//bool
ds = WS.GetAllCountries();
var v = WS.GetAllCountries();
ddlContinent.DataSource = v;
ddlContinent.DataBind();
}

View 5 Replies

Web Forms :: DropDown List Not Retaining The Values(the DropDown Inside Gridview Control)?

Jun 12, 2010

I Have the gridview control with 2 dropdown list and 2 text boxes,When the textbox chnaged event happen 1 row will create and the dropdown back to initial values( its not retaining the selected values),I am binding the control after text changed method,Is there any properties needs to be set or any other way we can retain the values in postbacks?

View 4 Replies

Fetch The Match Values Regarding One Dropdown To Another Dropdown?

Mar 19, 2011

in a web form, i am having two drop down controls, and in the first one control i am having, state names like some thing, and in another i have to fetch the concurrent city names for the first control, like if i select city name as 'A' it must fetch the related city names for the 'A' how could i do this.

View 2 Replies

DataSource Controls :: Removing Duplicates From Two Similar Columns Or Any Other Columns In A Database Schema

Apr 21, 2010

I have two columns first name and last name , that have duplicates, how can i remove the duplicates and only leave the distinct members intact?

View 6 Replies

Data Controls :: Check For Duplicates While Inserting Data From GridView To Database

Apr 27, 2014

How to check for duplicates before inserting in SQL Server inGridView in ASP.Net ....

View 1 Replies

Linq To Sql - MVC2 - Set ViewModel Values With Retrieved From Db Object's Values With DataAnnotations

Jan 8, 2011

Prior to using a ViewModel, I could easily pass the "soon to be edited" object directly to the view without needing to fuss over setting individual properties etc as the View conveniently accepted the Employee type directly..

[HttpGet]
public ActionResult EditEmployee(int? id)
{
EmployeeRepository ER = new EmployeeRepository();
Employee SomeEmployee = ER.GetEmployee(id.Value);
if(SomeEmployee!=null)
return View(SomeEmployee);

But now I'm using a ViewModel with DataAnnotations attributes applied over the top of various properties for validation purposes. Which creates a problem.. After fetching the "soon to be edited" object from the db, setting the ViewModel's values is suddenly a whole lot more complicated. I can't simply pass the retrieved object straight to the view, as the View now expects the VMEmployee type instead. I would like to be able to do something like:

[HttpGet]
public ActionResult EditEmployee(int? id)
{
EmployeeRepository ER = new EmployeeRepository();
Employee SomeEmployee = ER.GetEmployee(id.Value);
if(SomeEmployee!=null)
return View(new VMEmployee(SomeEmployee));

All paths seem to lead to a huge constructor which manually sets the values of each individual property. But I never had to do that before when I wasn't using a ViewModel. Model binding was a blessing! My objects also have complex child objects, which my form is also collecting values for, so this would be a huge/verbose task against DRY principals. I don't even really want to use a ViewModel, but am forced to because I need two different DataAnnotations rule sets for different validation scenarios applied to the same object.

All I want to do is be able to have two different DataAnnotations rule sets for different scenarios. I.e. public-facing www site vs internal-facing admin site. DataAnnotations doesn't seem to be flexible enough to easily cater for this common need. I've tried AutoMapper, but it throws an error saying it can't map my object types, I suspect because Employee was auto-generated by LINQ to SQL. What is the most elegant way to achieve this while sticking to DRY principals?

View 1 Replies

Bind BLL To A Dropdown?

May 3, 2010

I have a BLL where in I am getting all the values from a table. Now I want to populate a dropdown with one of the field from a BLL.

ddlstatus1.SelectedValue = dt.Rows(0).Item("StatusCode")

But the above code is not working.

I tried ddlstatus1.selectedindex = dt.Rows(0).Item("StatusCode") but it says that it cannot convert string to integer.

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved