SelectedIndexChanged方法内的DataTable声明不起作用

时间:2017-07-17 12:16:12

标签: c# asp.net variables datatable declaration

我正在尝试在dropdownchange方法中定义DataTable,如下所示:

protected void selectSegment_SelectedIndexChanged(object sender, EventArgs e)
{
    String query = "<View><Query><Where><Eq><FieldRef Name='Segment' /><Value Type='Lookup'>" + selectSegment.SelectedItem.Text + "</Value></Eq></Where></Query></View>";
    DataTable dt = SPCommon.GetFilteredItems("Approvers Info", "Business_x0020_Unit", "ID", query);
}
  

当我调试上面的代码时,我得到的错误为The name 'dt' does not exist in the current context

enter image description here 如果我在PageLoad上做同样的事情,可以正常工作:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {    
        DataTable Results = SPCommon.GetAllItems("Segments", "Title", "ID");
        System.Web.UI.WebControls.ListItem defalutListItem = new System.Web.UI.WebControls.ListItem();
        defalutListItem.Text = "Select";
        defalutListItem.Value = "-99";
        Common.populateDropdown(selectSegment, Results, "Title", "ID", defalutListItem);
        Results.Clear();
    }
}

请帮助理解为什么我无法在SelectedIndexChanged方法中声明新的DataTable变量?

1 个答案:

答案 0 :(得分:1)

尝试使用变量SELECT TRIM(UPPER(company_name)), vat, company_owner_email FROM ( (SELECT company_name, vat, admin.email as company_owner_email FROM pub LEFT JOIN admin ON pub.manager = admin.id WHERE company_name > '') UNION (SELECT company_name, vat, admin.email as company_owner_email FROM adv LEFT JOIN admin ON adv.manager = admin.id WHERE company_name > '') ) company GROUP BY UPPER(replace(company_name,' ','')) ORDER BY company_name; 执行某些操作,因为.net可能已经“优化”它(完全删除它),因为它不会在代码中的任何位置使用...