如何訪問page_load上的變量並在c#中使用ddlApp_SelectedIndexChanged方法? 謝謝如何從C#中的不同方法訪問變量?
private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlRole.SelectedIndex = 0;
}
string ddl = ddlApp.Value.ToString();
string ddlRoleDs;
string ddlMenuDs;
string GvDs;
if (ddl == "ATTD")
{
ddlRoleDs = "ddlAttdDs";
ddlMenuDs = "ddlMenuAttdDs";
GvDs = "AttdMenuAssignmentDs";
}
else if (ddl == "TRVL")
{
ddlRoleDs = "ddlTrvldDs";
ddlMenuDs = "ddlMenuTrvlDs";
GvDs = "TrvlMenuAssignmentDs";
}
}
變量:ddlRoleDs,GvDs和ddMenuDs
protected void ddlApp_SelectedIndexChanged(object sender, EventArgs e)
{
ddlRole.DataSourceID = ddlRoleDs;
MenuAssignmentGv.DataSourceID = GvDs;
ddlMenu.DataSourceID = ddlMenuDs;
}
如果這兩種方法都在同樣的類你可以使用全局變量 –