我需要在C#
中创建一个DataTable
。现在我的ascx
页面有两个TextBoxes
。一个用于学生ID txtStudentID
和一个用于学生名字txtStudentName
。它还有一个CheckBox
列表(ckbxPF),它有通过或失败。我需要根据用户输入创建一个带有这些值的DataTable
,然后返回表。基于文本框和复选框值创建数据表C#
此外,如果有人知道如何在不同的class
访问这些值将是伟大的!
任何帮助将不胜感激! 谢谢! -Tom
我需要在C#
中创建一个DataTable
。现在我的ascx
页面有两个TextBoxes
。一个用于学生ID txtStudentID
和一个用于学生名字txtStudentName
。它还有一个CheckBox
列表(ckbxPF),它有通过或失败。我需要根据用户输入创建一个带有这些值的DataTable
,然后返回表。基于文本框和复选框值创建数据表C#
此外,如果有人知道如何在不同的class
访问这些值将是伟大的!
任何帮助将不胜感激! 谢谢! -Tom
我必须承认,我不明白的问题,但确定,这里的创建数据表的一种方法:
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;}
是的,非常感谢你! –
现在我只需要在不同于创建数据表的其他类中使用其中的两个值。例如,我需要打印以下行:“StudentName”(文本框值)“通过”(复选框)。再次感谢! –
@TomBlouise:当你在不同的类中引用DataTable时(通过属性,Session,(静态)方法,构造函数,...),你只需要读第一行(因为只有一行表)来获得你的价值。 'string studentName = table.Rows [0] .Field
显示您拥有的信息并根据您的代码提出具体问题。 – JohnFx
我在Web控件上有两个文本框。这些文本框将有用户输入,我需要捕获该数据表中的输入。我需要在我的项目的不同类中使用存储在此数据表中的值。我还没有开始编码。 –