c# - Input string was not in a correct format in my gridview -
here, have attendance table having attributes such
status - bit, studid - bigint (foreign key), attendanceid - int =>primary key , identity(true)
and student table having
studid - bigint =>primary key, studfirstname - varchar(50), studlastname - varchar(50)
to displayed in gridview. here code :
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; public partial class class_content_addattendancesss : system.web.ui.page { dataclassesdatacontext db = new dataclassesdatacontext(); protected void page_load(object sender, eventargs e) { var cn = p in db.attendances (p.branchid == convert.toint32(dropdownlist1.selectedvalue)) && (p.semesterid == convert.toint32(dropdownlist2.selectedvalue)) select new { p.attendanceid, p.status, p.studid, p.student.studfirstname, p.student.studlastname, p.branchid, p.semesterid, p.branch.branchname, p.semester.semestername }; gridview1.datasource = cn; gridview1.databind(); } }
and in design :
<asp:label id="label1" runat="server" text='<%#eval("studid") %>'></asp:label> <asp:label id="label2" runat="server" text='<%#eval("studfirstname") %>'></asp:label> <asp:label id="label3" runat="server" text='<%#eval("studlastname") %>'></asp:label> <asp:checkbox id="checkbox1" text='<%#eval("status") %>' runat="server" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
assing data
text='<%# eval("studid").tostring() %>' text='<%# eval("status").tostring() %>'
or specify gridview columns integer type.
Comments
Post a Comment