2
public class VivaClass{
public VivaClass()
{
    StudentObJ = new StudentClass();
    StudentObJ.SetGetDGroupID = "";
    StudentObJ.SetGetDUserName = "";
    StudentObJ.SetGetDProjectName = "";
    StudentObJ.SetGetDCity = "";
    this.Date = "";
    this.Time = "";
    this.isMake = false;
}
public VivaClass(string date, string time, bool isMake, string Gid, string uName, string Prjct, string city)
{
    StudentObJ = new StudentClass(Gid, uName, Prjct, city);
    this.Date = date;
    this.Time = time;
    this.isMake = isMake;
}
public VivaClass(string date, string time, bool isMake, string uName,string city)
{
    StudentObJ = new StudentClass();
    StudentObJ.SetGetDUserName = uName;
    this.Date = date;
    this.Time = time;
    this.isMake = isMake;
    this.SetGetStudentObJ.SetGetDCity = city;
}
private StudentClass StudentObJ;

public StudentClass SetGetStudentObJ
{
    get { return StudentObJ; }
    set { StudentObJ = value; }
}
public int ID;

public int SetGet_ID
{
    get { return ID; }
    set { ID = value; }
}

private string Date;

public string SetGetDate
{
    get { return Date; }
    set { Date = value; }
}
private string Time;

public string SetGetDTime
{
    get { return Time; }
    set { Time = value; }
}
private bool isMake;

public bool SetGetDIsMake
{
    get { return isMake; }
    set { isMake = value; }
}

}

public List<VivaClass> ReturnVivaObj()
{
    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;
}

マークアップ

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

GridView バインディング コード

private void FillGrid()
{
    GridView1.DataSource = new StudentIdentity().ReturnVivaObj();
    GridView1.DataBind();

}

データをバインドしようとしていますが、VivaClass に「ID」という名前のプロパティが含まれていないという例外がスローされます。コードをバインドする方法がわかりません。これに対するリンクまたは解決策を教えてください。ありがとう

4

3 に答える 3

2

あなたの問題は、それIDが実際にに縛られようとしていることだと思いますgridView。の代わりにに変更public int ID;するpublic int ID { get;set;}か、にバインドSetGet_IDします。gridViewID

幸運を!

于 2012-10-19T19:20:22.167 に答える
1

In the grid view declaration try providing "SetGet_ID" instead of "ID" as shown below

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="SetGet_ID" ...>

Hope this Helps!!

于 2012-10-19T19:20:39.367 に答える
0

次の類推によって、コードとマークアップを書き直すことを検討してください。

public class VivaClass
{
    public VivaClass()
    {
        StudentObJ = new StudentClass();
        StudentObJ.GroupID = "";
        StudentObJ.UserName = "";
        StudentObJ.ProjectName = "";
        StudentObJ.City = "";
        this.Date = "";
        this.Time = "";
        this.isMake = false;
    }

    public VivaClass(string date, string time, bool isMake, string Gid, string uName, string Prjct, string city)
    {
        StudentObJ = new StudentClass(Gid, uName, Prjct, city);
        this.Date = date;
        this.Time = time;
        this.isMake = isMake;
    }
    public VivaClass(string date, string time, bool isMake, string name, string city)
    {
        Student = new StudentClass();
        Student.UserName = name;
        Student.City = city;
        Date = date;
        Time = time;
        IsMake = isMake;
    }

    public StudentClass Student { get; set; }

    public int ID { get; set; }

    public string Date { get; set; }

    public string Time { get; set; }

    public bool IsMake { get; set; }

    public IEnumerable<VivaClass> Vivas()
    {
        using (SqlConnection connection = new SqlConnection(new ConnectionString().GetConString(("SqlConString"))))
        {
            string query = "Select ID,GroupID,StudentName,ProjectName,City,Date,Time,isMake FROM SchedualTB";
            SqlCommand cmd = new SqlCommand(query, connection);
            connection.Open();
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    VivaClass obj = new VivaClass();
                    obj.ID = (int(dr["ID"];
                    obj.Student.GroupID = (string)dr["GroupID"];
                    obj.Student.StudentName = (string)dr["StudentName"];
                    obj.Student.ProjectName = (string)dr["ProjectName"];
                    obj.Student.City = (string)dr["City"];
                    obj.Date = (string)dr["Date"].ToString();
                    obj.Time = (string)dr["Time"];
                    obj.IsMake = (bool)dr["isMake"];
                    yield return obj;
                }
            }
        }
    }    
}

マークアップ:

<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") %>' />
             </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Student ID">
            <ItemTemplate>
                <asp:Label ID="lblUserName" runat="server" Text='<%# Eval("UserName") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Student Name">
            <ItemTemplate>
                <asp:Label ID="lblStudentName" runat="server" Text='<%# Eval("StudentName") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Project Name">
            <ItemTemplate>
                <asp:Label ID="lblProjectName" runat="server" Text='<%# Eval("ProjectName") %>' />
            </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" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
于 2012-10-20T05:21:09.807 に答える