var names = from s in dbc.Patient_Detail_Tables where s.Name.Contains(txtSearch.Text) select s;
listBox1.DataSource = names;
listBox1.DisplayMember = "Name";
listBox1.ValueMember = "RegitrationNo";
How to get the valuemember using Linq query?
How to get the valuemember using Linq query?

VulpesRank #55 · 29.2K reputationPosted Jul 17, 2012, 2:56 AM EDT
var names = (from s in dbc.Patient_Detail_Tables where s.Name.Contains(txtSearch.Text) select s).ToList();
paddu v49 reputationPosted Jul 17, 2012, 3:51 AM EDT
Sachin KaliaRank #102 · 20.8K reputationPosted Jul 17, 2012, 4:41 AM EDT
This is the code segment which can help you out somewhere :
div> asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"> asp:ListItem Value="One" Selected="True" /> asp:ListItem Value="Two" /> asp:ListItem Value="Three" /> asp:ListItem Value="Four" Selected="True" /> asp:ListItem Value="Five" /> asp:ListBox> br /> br /> asp:Button ID="btnSel" runat="server" Text="Get Selected" onclick="btnSel_Click" /> div>C#
protected void btnSel_Click(object sender, EventArgs e) { var selItems = from ListItem li in ListBox1.Items where li.Selected == true select li.Text; Response.Write("Selected Item(s): "); foreach (var item in selItems) { Response.Write(item.ToString() + ""); } } You can also refer this link : http://www.devcurry.com/2009/07/retrieve-selected-items-of-aspnet.html Cheers DotNet :)VulpesRank #55 · 29.2K reputationPosted Jul 17, 2012, 6:46 AM EDT
string s = ""; // default value, say, if SelectedValue is null
if (listBox1.SelectedValue != null)
{
s = listBox1.SelectedValue.ToString();
}