listbox selected items binding to gridview

Posted by Suneel161 under ASP.NET on 12/31/2010 | Points: 10 | Views : 9504 | Status : [Member] | Replies : 2
I have a listbox with multiple selected items in a tab panel and when i select items and move to the second tab the selected items should be shown in a gridview.




Responses

Posted by: Lalji_mer on: 12/31/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Related your question answer you will find here,please show below link


http://forums.asp.net/p/1618018/4146002.aspx

LP MER

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 12/31/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Suneel161,

Try the following code...I am try this code in button event...


DataTable dtData = new DataTable();
dtData.Columns.Add("Selected");

for(int x=0; x < ListBox1.Items.Count; x++)
{
if(ListBox1.Items[x].Selected.Equals(true))
{
DataRow dr = dtData.NewRow();
dr["Selected] = ListBox1.Items[x].Text;
dtData.Rows.Add(dr);
}
}


Finally you got a selected values in DataTable now bind that DataTable value into your GridView.


GridView1.DataSource = dtData.Copy();
GridView1.DataBind();


Happy New Year 2011

Cheers :)

Thanks,
T.Saravanan

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response