Please help me out, I am new to asp.net. my gridview have 5 columns and I want to bind two columns of this gridview to select data from database while user enter data through the other columns of the gridview in order to save the gridview data to another table. But I have problem with binding data to 2 columns out of 5 columns of the gridview. How can I achieve this. Here is my code
string classid = query.Class + query.Class_division;
var q = (from cl in db.StudentTbs where cl.Admission_class == classid select new {
id=cl.UnquieStudentId, Name= cl.Surname+", "+ cl.FirstName +" "+ cl.OtherName
}).ToList();
DataTable dt = new DataTable();
if(q.Count>0)
{
DataRow row = null;
dt.Columns.Add("Series No");
dt.Columns.Add("name");
foreach( var row2 in q)
{
row = dt.NewRow();
dt.Rows.Add(row2.id);
dt.Rows.Add(row2.Name);
}
GridView1.DataSourceID = null;
GridView1.DataSource = dt;
GridView1.DataBind();
}