获取选定的索引ID 0并且无法移动该项目

时间:2011-10-19 05:54:17

标签: asp.net datalist

我想选择我的代码为

的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();
    }

请有人帮助我,如何移动项目

1 个答案:

答案 0 :(得分:0)

我只添加了

        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

        }