我的gridview中的输入字符串格式不正确

时间:2014-04-24 08:22:48

标签: c# sql gridview data-binding

在这里,我有考勤表,其中包含

等属性
Status - bit, 
StudId - bigint (foreign key), 
AttendanceId - int =>primary key , identity(true) 

和学生表

StudID - bigint =>primary key, 
StudFirstName - varchar(50), 
StudLastName - varchar(50) 

在gridview中显示。 这是代码:

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 = from p in db.Attendances
             where (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();
}
}

在设计中:

                          

            <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>

1 个答案:

答案 0 :(得分:0)

将数据分配为

 Text='<%# Eval("StudId").ToString() %>'

 Text='<%# Eval("Status").ToString() %>'

或将gridview列指定为Integer类型。