Click here to Skip to main content
16,021,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,


I have a ListBox inside a Gridview. Now, I want to display selected Items of ListBox items into another Gridview.

Can anyone help me to do this.

C#
ListBox LstBox = (dgi.FindControl("lstType") as ListBox); 
string strselect = ""; 

for (int j = 0; j < LstBox.Items.Count; j++) 
{ 
	ListItem li = LstBox.Items[j]; 
        if (li.Selected)
         { 
          strselect = strselect + ", " + li.Value; 
         }
}

if (strselect.Length > 0) 
 {
 strselect = strselect.Remove(0, 2);
 } 

dr["Type"] = strselect;


Thanx in advance....
Posted
Updated 12-Sep-12 2:16am
v2
Comments
Vani Kulkarni 12-Sep-12 5:52am    
Please elaborate your question. Also post code on what you have tried.
[no name] 12-Sep-12 6:05am    
ListBox LstBox = (dgi.FindControl("lstType") as ListBox);
string strselect = "";
for (int j = 0; j < LstBox.Items.Count; j++)
{
ListItem li = LstBox.Items[j];
if (li.Selected)
{
strselect = strselect + ", " + li.Value;
}
}
if (strselect.Length > 0)
{
strselect = strselect.Remove(0, 2);
}
dr["Type"] = strselect;
Karthik Harve 12-Sep-12 5:52am    
What have tried so far ? can you show your code.
[no name] 12-Sep-12 6:05am    
ListBox LstBox = (dgi.FindControl("lstType") as ListBox);
string strselect = "";
for (int j = 0; j < LstBox.Items.Count; j++)
{
ListItem li = LstBox.Items[j];
if (li.Selected)
{
strselect = strselect + ", " + li.Value;
}
}
if (strselect.Length > 0)
{
strselect = strselect.Remove(0, 2);
}
dr["Type"] = strselect;

1 solution

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

DataRow dr = dtData.NewRow();
dr["Selected] = ListBox1.Selectedvalue.ToString();    
dtData.Rows.Add(dr);

GridView1.DataSource = dtData.Copy();
GridView1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900