Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据表的selectedIndexChanged在c中不起作用_C#_Visual Studio_Sharepoint 2010 - Fatal编程技术网

C# 数据表的selectedIndexChanged在c中不起作用

C# 数据表的selectedIndexChanged在c中不起作用,c#,visual-studio,sharepoint-2010,C#,Visual Studio,Sharepoint 2010,我已经实现了一个下拉列表,我想根据下拉列表中选择的值填充数据表。但目前我无法显示已更改的SelectedIndex。请帮忙 protected void ddlitem_SelectedIndexChanged(object sender, EventArgs e) { DataTable result = new DataTable(); result.Columns.Add("Supplier");

我已经实现了一个下拉列表,我想根据下拉列表中选择的值填充数据表。但目前我无法显示已更改的SelectedIndex。请帮忙

  protected void ddlitem_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable result = new DataTable();

            result.Columns.Add("Supplier");
            result.Columns.Add("Country");
            result.Columns.Add("Partnership Duration");
            result.Columns.Add("Partnership Type");

            int intMemberIndex = 0;
            try
            {
                foreach (SPListItem objtestListItem in objtestList.Items)
                {
                    string SupplierName = objtestListItem["Supplier"].ToString();
                    string Country = objtestListItem["Country"].ToString();
                    string PD = objtestListItem["Partnership Duration"].ToString();
                    string PT = objtestListItem["Partnership Type"].ToString();
                    intMemberIndex = objtestListItem.ID;

                    for (int i = 0; i < ddlitem.Items.Count; i++)
                    {
                        if (ddlitem.Items[i].Text.Equals(SupplierName))
                        {
                            result.Rows.Add(SupplierName, Country, PD, PT);


                        }
                    }

                } this.resultGrid.DataSource = result;
                this.resultGrid.Visible = true;
                this.resultGrid.DataBind();
            }
            catch (Exception ex)
            {

                lblTxt.Text = ex.Message;
            }


        }



    }

下拉列表的标记应该如下所示

<asp:DropDownList ID="ddlitem" AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddlitem_SelectedIndexChanged">
</asp:DropDownList>

你设置了Autopostback=true吗?@Dwayne Johnson:你说我无法显示所选索引是什么意思?使用场景是什么,预期和实际行为是什么?@Kangkan我正在从sharepoint列填充下拉列表,我希望从下拉列表中选择一个特定项目,并显示与从下拉列表中选择的项目匹配的相关列。@V4Vendetta我没有设置Autopostback=true。你在哪里设置的?@V4Vendetta ok会试试。if语句做什么?@DwayneJohnson
if(!Page.IsPostBack)
{
   //Control Initialization
   //Databinding
}