enter code herepublic List<VivaClass> ReturnVivaObj() //viva class all field is private
{
List<VivaClass> Objlst = new List<VivaClass>();
VivaClass obj = null;
try
{
SqlConnection hookup = new SqlConnection(new ConnectionString().GetConString(("SqlConString")));
string query = "Select ID,GroupID,StudentName,ProjectName,City,Date,Time,isMake FROM SchedualTB";
SqlCommand cmd = new SqlCommand(query, hookup);
hookup.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
obj = new VivaClass();
obj.SetGet_ID = Convert.ToInt32(dr["ID"]);
obj.SetGetStudentObJ.SetGetDGroupID = Convert.ToString(dr["GroupID"]);
obj.SetGetStudentObJ.SetGetDStudentName = Convert.ToString(dr["StudentName"]);
obj.SetGetStudentObJ.SetGetDProjectName = Convert.ToString(dr["ProjectName"]);
obj.SetGetStudentObJ.SetGetDCity = Convert.ToString(dr["City"]);
obj.SetGetDate = dr["Date"].ToString();
obj.SetGetDTime = dr["Time"].ToString();
obj.SetGetDIsMake = Convert.ToBoolean(dr["isMake"].ToString());
Objlst.Add(obj);
}
}
catch (Exception e)
{
throw e;
}
return Objlst;
}
enter code herepublic List<VivaClass> ReturnVivaObj() // this function return the list of viva objec for binding the Gridview control
{
List<VivaClass> Objlst = new List<VivaClass>();
VivaClass obj = null;
try
{
SqlConnection hookup = new SqlConnection(new ConnectionString().GetConString(("SqlConString")));
string query = "Select ID,GroupID,StudentName,ProjectName,City,Date,Time,isMake FROM SchedualTB";
SqlCommand cmd = new SqlCommand(query, hookup);
hookup.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
obj = new VivaClass();
obj.SetGet_ID = Convert.ToInt32(dr["ID"]);
obj.SetGetStudentObJ.SetGetDGroupID = Convert.ToString(dr["GroupID"]);
obj.SetGetStudentObJ.SetGetDStudentName = Convert.ToString(dr["StudentName"]);
obj.SetGetStudentObJ.SetGetDProjectName = Convert.ToString(dr["ProjectName"]);
obj.SetGetStudentObJ.SetGetDCity = Convert.ToString(dr["City"]);
obj.SetGetDate = dr["Date"].ToString();
obj.SetGetDTime = dr["Time"].ToString();
obj.SetGetDIsMake = Convert.ToBoolean(dr["isMake"].ToString());
Objlst.Add(obj);
}
}
catch (Exception e)
{
throw e;
}
return Objlst;
}
enter code here<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" onrowediting="GridView1_RowEditing">
<Columns>
<asp:TemplateField HeaderText="Group ID">
<ItemTemplate>
<asp:Label ID="lblGroupID" runat="server" Text='<%# Eval("GroupID") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student ID">
<ItemTemplate>
<asp:Label ID="lblUserName" runat="server" Text='<%# Eval("UserName") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Name">
<ItemTemplate>
<asp:Label ID="lblStudentName" runat="server" Text='<%# Eval("StudentName") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Project Name">
<ItemTemplate>
<asp:Label ID="lblProjectName" runat="server" Text='<%# Eval("ProjectName") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Right" HeaderText="Status" >
<ItemTemplate>
<asp:ImageButton ID="imgStatus" runat="server" CommandName="Edit" ToolTip="Change User status" ImageUrl="~/Image/logo/statusActive.png"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
enter code hereprivate void FillGrid() // Error: 'VivaClass' does not contain a property with the name 'ID'
{
GridView1.DataSource = new StudentIdentity().ReturnVivaObj();
GridView1.DataBind();
}
我试图绑定数据,但异常抛出VivaClass不包含名称为'ID'的属性。我不知道如何通过代码绑定。可以任何一次给我任何链接或解决方案。感谢