문제

현재 ASP .NET Formview를 프로그래밍하고 있습니다. 여기서 트위스트는 DataSource를 수동으로 설정해야한다는 것입니다. "formview.datasource =". 나는 추가했다 ItemTemplate 양식보기에 일부 양식을 추가했지만 데이터 소스보기를 설정하는 코드 라인이 호출되고 formview.databind () 여전히 데이터를 볼 수 없습니다.

그런 다음 아마도보기가 항목보기 나 무언가에 있지 않다고 생각했습니다. 그래서 나는 기본 모드 전체 코드를 편집하고 배치합니다 itemedIttemplate 그러나 Databind를 통해 전달할 때 여전히 양식이 표시되지 않습니다.

ASPX 태그에 설정된 데이터 소스를 사용 하여이 작업을 수행하면 작동했음을 알고 있습니다. 그러나 불행히도 내 요구 사항은 ASP .NET에서 DataSource 태그를 사용하는 것이 아니라 바인딩을 수동으로 수행하는 것입니다.

거기에 아이디어 나 예제 수동 데이터베이닝에서 Formview를 사용하는 방법이 있습니까?

도움이 되었습니까?

해결책

이 코드를보고

사용자 정의 데이터 소스 클래스,

namespace dc
{
    public class Student
    {
        public int Roll { get; set; }
        public string Name { get; set; }
        public Student() { }
        public Student(int _roll, string _name)
        {
            Roll = _roll;
            Name = _name;
        }
    }
    public class StudentList : List<Student>
    {

    }
}

ASPX 마크 업,

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        dc.StudentList a = new dc.StudentList();
        a.Add(new dc.Student(1, "A"));
        a.Add(new dc.Student(2, "A"));

        FormView1.DataSource = a;
        FormView1.DataBind();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Sample</title>
</head>
<body>
     <form id="form1" runat="server">
    <asp:FormView ID="FormView1" AllowPaging="true"  runat="server">
      <ItemTemplate>
          <asp:Label ID="Label1" runat="server" Text='<%# Eval("Roll") %>'></asp:Label>
          <asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
      </ItemTemplate>
    </asp:FormView>
    </form>
</body>
</html>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top