我的Gridview下拉列表是刷新

我的Gridview下拉列表是刷新

本文介绍了我的Gridview下拉列表是刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Gridview DropDownList,它具有DataTextField和DataValueField.

下拉列表---> CMBITem

当我选择项目时,费率"将显​​示在Gridview文本框上.但是每次我选择项目"时,下拉列表都会刷新,已选择的项目"不会显示.

I have Gridview DropDownList, which has DataTextField and DataValueField.

Dropdownlist---> CMBITem

When I Select the Item, The Rate will be display on Gridview TextBox. But everytime the I select the Item the Dropdown list is refresh, Already Selected Item is not display.

protected void CMBItem_SelectedIndexChanged(object sender, EventArgs e)
   {
       DropDownList lb = (DropDownList)sender;
       GridViewRow gvRow = (GridViewRow)lb.NamingContainer;
     int rowID = gvRow.RowIndex;
       if (ViewState["CurrentTable"] != null)
       {
           DataTable dt = (DataTable)ViewState["CurrentTable"];

           connect.cn();
           SqlCommand sqlcmd = new SqlCommand("Get_Item_PurchasePrice", connect.cn());
           sqlcmd.Parameters.AddWithValue("@IMSNO", lb.SelectedValue);
          sqlcmd.CommandType = CommandType.StoredProcedure;
          SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
           DataTable dt1 = new DataTable();
           da.Fill(dt1);
           if (dt1.Rows.Count > 0)
           {
               dt.Rows[rowID][4] = dt1.Rows[0][0].ToString();
               dt.Rows[rowID][5] = dt1.Rows[0][1].ToString();

         }
           ViewState["CurrentTable"] = dt;
           //Re bind the GridView for the updated data
           Gridview2.DataSource = dt;
           Gridview2.DataBind();
       }
     SetPreviousData();
   }


 private void SetPreviousData()
   {

       int rowIndex = 0;

       if (ViewState["CurrentTable"] != null)
       {

           DataTable dt = (DataTable)ViewState["CurrentTable"];

           if (dt.Rows.Count > 0)
           {
               AddGridcombo();
               LoadItemList();

               for (int i = 0; i < dt.Rows.Count; i++)
               {
                  DropDownList box4 = (DropDownList)Gridview2.Rows[rowIndex].Cells[1].FindControl("CMBGodown");
                  DropDownList box7 = (DropDownList)Gridview2.Rows[rowIndex].Cells[1].FindControl("CMBItem");

                   TextBox box1 = (TextBox)Gridview2.Rows[rowIndex].Cells[2].FindControl("txtqty");
                   TextBox box2 = (TextBox)Gridview2.Rows[rowIndex].Cells[3].FindControl("txtrate");
                   TextBox box3 = (TextBox)Gridview2.Rows[rowIndex].Cells[4].FindControl("txttaxpercent");
                   TextBox box5 = (TextBox)Gridview2.Rows[rowIndex].Cells[5].FindControl("txttaxvalue");
                   TextBox box6 = (TextBox)Gridview2.Rows[rowIndex].Cells[6].FindControl("txtamt");
                   box4.Text = dt.Rows[i]["Column1"].ToString();
                   box1.Text = dt.Rows[i]["Column3"].ToString();
                   box2.Text = dt.Rows[i]["Column4"].ToString();
                   box3.Text = dt.Rows[i]["Column5"].ToString();
                   box5.Text = dt.Rows[i]["Column6"].ToString();
                   box6.Text = dt.Rows[i]["Column7"].ToString();
                   box7.Text = dt.Rows[i]["Column2"].ToString();

                   rowIndex++;


              }

             // dtCurrentTable.Rows.Add(drCurrentRow);
             ViewState["CurrentTable"] = dt;
            //  Gridview2.DataSource = dt;
              //Gridview2.DataBind();
             // AddGridcombo();

           }
       }

private void LoadItemList()
   {
       try
       {
            connect.cnopen();
       foreach (GridViewRow grdRow in Gridview2.Rows)
       {
          DropDownList drdlist = (DropDownList)(Gridview2.Rows[grdRow.RowIndex].Cells[2].FindControl("CMBItem"));

        //   BeginTransaction("LoadItemList");
          // SqlCommand sqlcmd = new SqlCommand("FETCH_PURCHASE_DTL_SP",connect.cn());
           SqlCommand sqlcmd = new SqlCommand("FETCH_ITEM_LIST_SP", connect.cn());
                sqlcmd.CommandType=CommandType.StoredProcedure;
         SqlDataAdapter da=new SqlDataAdapter(sqlcmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
               drdlist.DataSource = dt;
              drdlist.DataValueField = "IM_SERIALNO";
               drdlist.DataTextField = "IM_ITEMNAME";
           drdlist.DataBind();

       }
       }
       catch { }
   }

推荐答案



这篇关于我的Gridview下拉列表是刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:01