0

を作成する必要がありDataTableますC#。現在、私のascxページには 2 つのTextBoxes. 1 つは学生 ID 用txtStudentID、もう 1 つは学生名用txtStudentNameです。また、CheckBox合格または不合格のリスト (ckbxPF) もあります。DataTableユーザー入力に基づいてこれらの値を使用して を作成し、テーブルを返す必要があります。

また、誰かが別の方法でそれらの値にアクセスする方法を知っていれば、classそれは素晴らしいことです!!

どんな助けでも大歓迎です!ありがとう!-トム

4

1 に答える 1

0

質問を理解していないことを認めなければなりませんが、DataTable を作成する 1 つの方法を次に示します。

DataTable table = new DataTable();
table.Columns.Add("StudentID", typeof(int));
table.Columns.Add("StudenName", typeof(string));
table.Columns.Add("Passed", typeof(bool));

int studentID = int.Parse(txtStudentID.Text);
String studentName = txtStudentName.Text;
bool passed = ckbxPF.SelectedIndex == 0; // assuming that "passed" is the first item

table.Rows.Add(studentID, studentName, passed);

DataTableたとえば、クラスのメソッドから返すか、またはそのクラスへの参照がある場合は、プロパティを介してこれを渡すことができます。次に例を示します。

// somewhere in Class2
DataTable table = class1.Table;

//in Class1, initialize this table from where you want
public DataTable Table { get; set;}
于 2012-09-18T22:47:19.277 に答える