디자인 및 코드를 처리하는 웹 양식 인 ASPX 페이지가 있습니다. 나는이 페이지에서 내가 가지고있는 모든 수업이 그들 자신의 파일로 분리되어야한다고 들었다. 이러한 파일은 클래스 이름과 동일한 이름을 가져야합니다. 내 ASPX 파일은 default.aspx이고 내 클래스는 GetMachineInfo.cs입니다. 내 ASPX 파일에서 해당 CS 파일을 호출하여 내 클래스가 ASPX 페이지 내부에있는 것처럼 보이게하려면 어떻게해야합니까? 필요한 경우 일부 코드를 삽입합니다. 실제 문제에 집중하기 위해 일부 코드를 잘라 냈습니다. 중괄호가 없거나 그 때문에 뭔가가있는 경우. 이 특정 문제에 필요한 정보를 제공하기 만하면됩니다. 건배.내 ASPX 페이지에서 C# 클래스 호출
namespace PVDA.Web
{
/*
* LINQ Queries for binding
* This is calling the wrong information
* It's calling the n attribute of "srn", not the mach "n"
* This is going a layer too deep. needs to be mach no srn
*/
public class Machine
{
// Getting all the objects to the machine
public int snsrN { get; set; }
public string calctype { get; set; }
public string sensName { get; set; }
public static List<Machine> GetMachineInfo(XDocument xDoc, int machineNumber)
{
return xDoc.XPathSelectElements("./mmsdata/mill/mach")
.Where(x => x.Attribute("n").Value == machineNumber.ToString())
.Elements()
.Select(x => new Machine
{
sensName = x.Value,
snsrN = Convert.ToInt32(x.Attribute("n").Value),
calctype = x.Attribute("calctype").Value
}).ToList();
}
}
}
namespace PVDA.Web
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Calling
ddlBinding();
NewQuery();
}
}
public void ddlBinding()
{
// Getting the XML file imported in
const string FILE_PATH = @"MillData.xml";
// Set the file path
XDocument xDoc = XDocument.Load(Server.MapPath(FILE_PATH));
Machine machine = new Machine();
// Setting a variable to bind the data into the dropdownlists
var dropDownDataList1 = GetMillInfo(xDoc, "n");
var dropDownDataList2 = machine.GetMachineInfo(xDoc, 2);
// Bind Machines to DropDownList2
DropDownList2.DataSource = machine.GetMachineInfo(xDoc, 2);
// Set text/value properties
DropDownList2.DataTextField = "snsrN";
DropDownList2.DataValueField = "sensName";
// Bind the contents to be reflected in the UI
DropDownList2.DataBind();
}
여전히 _defualt.Machine는 "DropDownList2.DataSource = Machine.GetMachineInfo와 GetMachineInfo에 대한 정의를 포함하지 않는 오류를 받고 (xDoc, 2), 그리고 또한 GetMachineInfo으로하여 XDocument를 찾는 여부 변수의 ... 솔직하게 추가하는 것을 잊어 버린 단순한 것 같아 –
바인딩 메소드를 실제 메소드 (즉,'dllBinding()'에 넣어야합니다. 적절한 using 문을 추가해야 할 수도 있습니다 XDocument 클래스를 마우스 오른쪽 버튼으로 클릭하고 Visual Studio에서 "Resolve"옵션을 확인하십시오. 그러면 Visual Studio에서 적절한 using 문을 자동으로 추가해야합니다. 'Machine' 클래스를 다른 파일에 포함시키고 참조하십시오. 그것도 잘해라. –
[분리 된 파일의 모습을 보여주는 요점은 여기를 참조하십시오.] (https://gist.github.com/Rionmonster/708305a93bc6060b0c99efa7fb0494af). –