Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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
Asp.net 正在获取所选索引id 0,无法移动该项_Asp.net_Datalist - Fatal编程技术网

Asp.net 正在获取所选索引id 0,无法移动该项

Asp.net 正在获取所选索引id 0,无法移动该项,asp.net,datalist,Asp.net,Datalist,我想选择我的代码所在的datalist的索引id protected void dlst1_SelectedIndexChanged1(object sender, EventArgs e) { indexId = Convert.ToInt32(dlst1.DataKeys[dlst1.SelectedIndex]); } 我根据所选的项目索引将项目从左向右移动,但我得到的是indexId 0,其交换方向相反,它应该从左向右移动,但它从右向左移动 pro

我想选择我的代码所在的datalist的索引id

 protected void dlst1_SelectedIndexChanged1(object sender, EventArgs e)
    {
       indexId = Convert.ToInt32(dlst1.DataKeys[dlst1.SelectedIndex]);

    }
我根据所选的项目索引将项目从左向右移动,但我得到的是indexId 0,其交换方向相反,它应该从左向右移动,但它从右向左移动

  protected void btnMoveright_Click(object sender, ImageClickEventArgs e)
    {
        List<ArrayList> temp = 1path;
        ArrayList temp2 = temp[indexId];
        temp[indexId] = temp[indexId + 1];
        temp[indexId + 1] = temp2;
        for (int i = 0; i < temp.Count; i++)
        {
            ArrayList lst = temp[i];
            tb.Rows.Add(Convert.ToInt32(lst[0]), lst[1].ToString(), lst[2].ToString(), i);

        }
        dlst1.DataSource = tb;
        DataBind();

        path = BaseDAL.GetImg(Ids);
        for (int i = 0; i < path.Count; i++)
        {
            ArrayList lst = path[i];
            tb.Rows.Add(Convert.ToInt32(lst[0]), lst[1].ToString(), lst[2].ToString(), i);

        }
        dlst2.DataSource = tb;
        DataBind();
    }
protectedvoidbtnmoveright\u单击(对象发送方,图像单击事件参数e)
{
列表温度=1路径;
ArrayList temp2=温度[indexId];
温度[indexId]=温度[indexId+1];
温度[indexId+1]=温度2;
对于(int i=0;i
请有人帮助我,如何移动我只添加的项目

        int c = 0;
        foreach (ArrayList x in temp)
        {
            if (indexId == Convert.ToInt32(x[0]))
            {
                break;
            }
            c++;
        }
        if ((temp.Count - 1) > c)
        {
         // my old code
         // only replaced indexId to c. Now i am able to move the item

        }

您是否在pageload函数中绑定数据列表而不选中IsPostBack?是的,但如果我选中IsPostBack,则无法在datalist中上载图像您是否也可以添加pageload函数?让我们看看如何修复它。@Ahmet Kakıcıd:我不认为这是在pageload上绑定数据列表的问题,我在数据列表中有一些项目,我在获取id时选择了一个,当我点击数据列表indexId外侧的moveright btn时,indexId变为0,当我将int indexId变为静态int indexId时,我得到id,但显示索引超出范围。必须为非负数且小于集合的大小。参数名称:ArrayList temp2行中的索引=temp[indexId];