C# 在我的gridview中,输入字符串的格式不正确
在这里,我有一个具有如下属性的考勤表C# 在我的gridview中,输入字符串的格式不正确,c#,sql,gridview,data-binding,C#,Sql,Gridview,Data Binding,在这里,我有一个具有如下属性的考勤表 Status - bit, StudId - bigint (foreign key), AttendanceId - int =>primary key , identity(true) <asp:Label ID="Label1" runat="server" Text='<%#Eval("StudId") %>'></asp:Label> <asp:
Status - bit,
StudId - bigint (foreign key),
AttendanceId - int =>primary key , identity(true)
<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>
学生桌上有
StudID - bigint =>primary key,
StudFirstName - varchar(50),
StudLastName - varchar(50)
<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>
要在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>
在设计上:
<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>
<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>
将数据分配为
<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>
Text='<%# Eval("StudId").ToString() %>'
Text='<%# Eval("Status").ToString() %>'
Text=''
文本=“”
或者将gridview列指定为整数类型。下拉列表1.SelectedValue和下拉列表2.SelectedValue的确切含义是什么?您当前的文化背景是什么?问题是什么?您不应该使用下拉列表,但在解析
时,Convert.ToInt32
可能会失败。SelectedValues
DropDownList是一个分支和学期列表,因此集成了可编辑的gridview…但它显示Gridview1.DataBind()中出现“输入字符串格式不正确”错误;请尝试使用cn.ToList()。同时编辑StudID和模板StudID
<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>