Gridview as follows
CourseName Courseincharge
i have two listbox as follows
Listbox1 as CourseName as follows
MFA
AFF
CTF
Listbox2 as Courseincharge as follows
Ramesh
Kumar
Sathish
From Listbox i want to display into above gridview.
for that how can i do using asp.net
Loading
Satyapriya NayakPosted Jan 1, 2014, 10:02 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication11
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lstbox.Items.Add("a");
lstbox.Items.Add("b");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", Type.GetType("System.String"));
dt.Columns.Add("Value", Type.GetType("System.String"));
foreach (ListItem lst in lstbox.Items)
{
DataRow dr = dt.NewRow();
dr["Name"] = lst.Text;
dr["Value"] = lst.Value;
dt.Rows.Add(dr);
}
grd.DataSource = dt;
grd.DataBind();
}
}
}