Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display the list box data into grid view i tried but my below code is not working.

My code as follows


Listbox1 as follows
Raj
suresh
Gopi
Vignesh
Ram

Listbox2 as follows
GM
IT
Acts
Rec
Hardware


protected void Page_Load(object sender, EventArgs e)
{

Gridviewimage.Visible = true;
ListBox1.Items.Add("Raj");
ListBox1.Items.Add("suresh");
ListBox1.Items.Add("Gopi");
ListBox1.Items.Add("Vignesh");
ListBox1.Items.Add("Ram");

ListBox2.Items.Add("GM");
ListBox2.Items.Add("IT");
ListBox2.Items.Add("Acts");
ListBox2.Items.Add("Rec");
ListBox2.Items.Add("Hardware");


DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Dpt", typeof(string));

if (ListBox1.Items.Count == ListBox2.Items.Count)
{
for (int i = 0; i < ListBox1.Items.Count; i++)
{
dt.Rows.Add(ListBox1.Items[i].Text, ListBox2.Items[i].Text);
}
Gridviewimage.DataSource = dt;
Gridviewimage.DataBind();
}
}



When i execute my above code in Gridview no data is there it shows the empty gridview.

what is the problem in my above code please help me.

regards,
Narasiman P.
Posted
Comments
Karthik_Mahalingam 12-Jan-14 8:23am    
post your girdview aspx code

1 solution

Enable the AutoGenerateColumns

C#
Gridviewimage.AutoGenerateColumns = true;
Gridviewimage.DataSource = dt;
Gridviewimage.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