0

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();
}

Image code

1
  • Pls dont include text images. Commented Mar 19, 2018 at 0:44

1 Answer 1

1

Format your GridView1 in your as below

<asp:GridView ID="GridView1"runat="server" AutoGenerateColumns="false">
<columns>
<asp:BoundField HeaderText="Series No" DataField="Series No" />
<asp:BoundField HeaderText="Name" DataField="name" />
</columns>
</asp:GridView>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.