Hi,
Here I'm providing some code for your requirement.
Just check once this it can helps you to get solution
<asp:listbox id="ListBox1" runat="server" selectionmode="Multiple" xmlns:asp="#unknown">
Height="176px" Width="130px" ></asp:listbox><br />
<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" xmlns:asp="#unknown" /><br />
<asp:datalist id="DataList1" runat="server" xmlns:asp="#unknown">
<HeaderTemplate >
<table width="100%" align="center">
<tr>
<td>Company ID</td>
<td>Company Name</td>
<td>Company Addr</td>
<td>Company Url</td>
</tr>
</HeaderTemplate>
<itemtemplate>
<tr>
<td><![CDATA[</td>
<td><![CDATA[</td>
<td><![CDATA[</td>
<td><![CDATA[</td>
</tr>
</itemtemplate>
<footertemplate>
</footertemplate></table>
</asp:datalist>
And the code behind file contains
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
filllist();
}
}
public void filllist()
{
TestingDBLinqDataContext db = new TestingDBLinqDataContext();
var d = from w in db.CompanyTabs
select new {id=w.id,cname=w.compname };
foreach (var h in d)
{
ListBox1.Items.Add(new ListItem(h.cname, h.id.ToString ()));
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int[] st=ListBox1.GetSelectedIndices ();
string sd="";
for(int i=0;i<st.length mode="hold" /> {
int h=st[i];
if(i==0)
{
sd=ListBox1.Items [h].Value ;
}
else
{
sd=sd+","+ListBox1.Items [h].Value ;
}
}
SqlConnection con = new SqlConnection(@"dbconnectionstring");
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select * from CompanyTab where id in ("+sd+")", con);
da.Fill(dt);
DataList1.DataSource = dt;
DataList1.DataBind();
}
All the Best