AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Tuesday 26 January 2016

Show, more than one column data in Drop Down text field in Asp.Net.

In this article I will discuss How to show, more than one column data in Drop Down text field in Asp.Net? Let's I want to show Name as a combination of columns (First Name & Last Name). Please check below given code How I do it?

Code:
var _UserList = GetUsers(); //Fetching User Data
var UserQuery = _UserList.Select(p => new { UserId = p.UserNum, DisplayText = p.FirstName + " " + p.LastName });

ddluser.AppendDataBoundItems = true;
ddluser.DataTextField = "DisplayText";
ddluser.DataValueField = "UserId";
ddluser.DataSource = UserQuery;
ddluser.DataBind();
ddluser.Items.Insert(0, (new ListItem() { Value = "0", Text = "Select" }));

In above code DisplayText is combination of FirstName & LastName

0 comments :

Post a Comment

  • Popular Posts
  • Comments