aspx 페이지가 처음로드 될 때 데이터 테이블을 만들고 싶습니다. 클래스 파일에 빈 행이있는 데이터 테이블을 만들기 위해 코드를 배치했습니다. 아래는 데이터 테이블을 생성하는 코드입니다. 파일 뒤에 내 코드에서 datagrid에 데이터 테이블 바인딩 (개별 클래스의 코드) 및 페이지로드시 데이터 테이블 코드 실행 C# ASP.NET
public class PaymentDetailsDataTable
{
public PaymentDetailsDataTable()
{
DataTable pventries = new DataTable();
DataColumn col1 = new DataColumn("col1");
DataColumn col2 = new DataColumn("col2");
DataColumn col3 = new DataColumn("col3");
DataColumn col4 = new DataColumn("col4");
DataColumn col5 = new DataColumn("col5");
DataColumn col6 = new DataColumn("col6");
DataColumn col7 = new DataColumn("col7");
DataColumn col8 = new DataColumn("col8");
DataColumn col9 = new DataColumn("col9");
col1.DataType = System.Type.GetType("System.Int32");
col2.DataType = System.Type.GetType("System.String");
col3.DataType = System.Type.GetType("System.String");
col4.DataType = System.Type.GetType("System.String");
col5.DataType = System.Type.GetType("System.String");
col6.DataType = System.Type.GetType("System.String");
col7.DataType = System.Type.GetType("System.String");
col8.DataType = System.Type.GetType("System.Double");
col9.DataType = System.Type.GetType("System.String");
pventries.Columns.Add(col1);
pventries.Columns.Add(col2);
pventries.Columns.Add(col3);
pventries.Columns.Add(col4);
pventries.Columns.Add(col5);
pventries.Columns.Add(col6);
pventries.Columns.Add(col7);
pventries.Columns.Add(col8);
pventries.Columns.Add(col9);
pventries.Rows.Add();
}
}
, 내 클래스의 인스턴스를 다음과 같이 다음과 같이 사용하는 것을 시도했다 :
public partial class create_pv : System.Web.UI.Page
{
String conn = WebConfigurationManager.ConnectionStrings["pvconn"].ToString();
PaymentDetailsDataTable pmd = new PaymentDetailsDataTable();
protected void Page_Load(object sender, EventArgs e)
{
/**/if(!IsPostBack)
pmd.PaymentDetailsDataTable();
allpventries.DataSource = pmd;
allpventries.DataBind();
}
}
을 지금 내가 얻을이 pmd.PaymentDetailsDataTable()
같은 방법 PaymentDetailsDataTable
에 액세스하려고 할 때 오류
'PaymentDetailsDataTable' does not contain a definition for 'PaymentDetailsDataTable' and no extension method 'PaymentDetailsDataTable' accepting a first argument of type 'PaymentDetailsDataTable' could be found (are you missing a using directive or an assembly reference?)
다음 나는 그것이 작동 무효 내 방식 반환 유형 (PaymentDetailsDataTable
)을 변경하지만 나중에 결합하려면 데이터 테이블을 그리드 뷰 (allpventries)에 추가하면 컴파일러 오류가 발생합니다.
코드베이스가 다른 클래스에있는 데이터 테이블에서 DataGrid를 바인딩하는 방법은 무엇입니까? 나중에 데이터 테이블에 새 행을 추가 할 것입니다. 이를 달성하기위한 대체 옵션도 허용됩니다.
객체 지향 프로그래밍 및 C# ASP.NET의 새로운 기능입니다.
감사합니다. 코드 스 니펫과 Tim Schmelter 코드를 가져 와서 작동합니다. – MaxI