Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 dropdownlist in gridview. Dropdownlist selected indexchanged event,i have bank name,branch,account,corresponding branch
JavaScript
$acoount_depending
on the bank name i've already used dropdownlist on selecteditem. Text to get text and value to assign as value. i've also assigned value to another column but while I'm adding new row previously set selectedvalue is cleared. plse reply me..thanks

This my code:
C#
  protected void btnAddBnkDtls_Click(object sender, EventArgs e)//rosna
        {            
            DataTable dt = blSupplierObj.BindBnkDtlsGrid(ref GrdvewBnkDetls);
            DataRow dr = dt.NewRow();
            
            dt.Rows.Add(dr);
            ViewState["dtBnk"] = dt;
            rowid = 0;
            GrdvewBnkDetls.DataSource = dt;
            GrdvewBnkDetls.DataBind();           
        }

        protected void GrdvewBnkDetls_RowDataBound(object sender, GridViewRowEventArgs e)
        {            Trace.Write("ADMIN.Master.frmPartySupplier_Customer.GrdvewBnkDetls_RowDataBound");

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowIndex != -1)
                {

                        e.Row.Cells[0].Text = Convert.ToString((e.Row.RowIndex + 1));
                        DropDownList ddlBank = (DropDownList)e.Row.FindControl("ddlBnkNme");
                        ddlBank.DataSource = dtBankDetails;
                        ddlBank.DataTextField = "Name";
                        ddlBank.DataValueField = "Uoid";
                        ddlBank.DataBind();
                        DataTable dt = (DataTable)ViewState["dtBnk"];
                        if (dt != null)
                        {
                            if (rowid < dt.Rows.Count)
                            {
                                ddlBank.SelectedValue = dt.Rows[rowid]["BankName"].ToString();
                            }
                            if (ddlBank.SelectedValue != "0")
                            {
                                DropDownList ddlBranch = (DropDownList)e.Row.FindControl("ddlBrnch");
                                blSupplierObj.BindCombo(ref ddlBranch, "Uoid", "Name", "SELECT Uoid,Name fROM CFN_TB_BankBranch Where FK_BankID ='" + ddlBank.SelectedValue + "' ");
                                if (dt.Rows[rowid]["Branch"].ToString() != "0")
                                    ddlBranch.SelectedValue = dt.Rows[rowid]["Branch"].ToString();
                            }
                            DropDownList ddlAcount = (DropDownList)e.Row.FindControl("ddlAccnt");
                            ddlAcount.DataSource = dtAccount;
                            ddlAcount.DataTextField = "Name";
                            ddlAcount.DataValueField = "Uoid";
                            ddlAcount.DataBind();
           
                            string str = DataBinder.Eval(e.Row.DataItem, "Account").ToString().Trim();
                            if (str != "")
                            {
                                ddlAccount.SelectedValue = str;
                            }
                        }
                        else
                        {
                            DropDownList ddlAcount = (DropDownList)e.Row.FindControl("ddlAccnt");
                            ddlAcount.DataSource = dtAccount;
                            ddlAcount.DataTextField = "Name";
                            ddlAcount.DataValueField = "Uoid";
                            ddlAcount.DataBind();
                        }
                }
            }
        }

        protected void GrdvewBnkDetls_RowCommand(object sender, GridViewCommandEventArgs e)//rosna
        {
            Trace.Write("ADMIN.Master.frmPartySupplier_Customer.GrdvewBnkDetls_RowCommand");
            GridViewRow objGridViewRow = (GridViewRow)((ImageButton)e.CommandSource).Parent.Parent;

            if (e.CommandName == "onDelete")
            {
                DataTable dt = blSupplierObj.BindBnkDtlsGrid(ref GrdvewBnkDetls);
                if (dt.Rows.Count > 0)
                {
                    int id = int.Parse(objGridViewRow.Cells[0].Text);
                    BL_PartySupplier_Customer.Tablefilter(ref dt, "  RowID <> " + id.ToString());
                    rowid = 0;
                    GrdvewBnkDetls.DataSource = dt;
                    GrdvewBnkDetls.DataBind();
                    ViewState["dtBnk"] = dt;                    
                }
                else
                {
                }
            }
        }
public string GetBankDtils(ref GridView GrdvewBnkDetls, string buttonText, ENT_PartySupplier_Customer entbnkObj)
       {
           //...
           StringBuilder strQuery = new StringBuilder();
           string strQuerys = string.Empty;
           if (GrdvewBnkDetls.Rows.Count >= 1 &&
              (GrdvewBnkDetls.Rows[0].FindControl("ddlBnkNme") as DropDownList).SelectedValue != "0")
           {
               for (int i = 0; i < GrdvewBnkDetls.Rows.Count; i++)
               {
                   //--
                   strQuery.Append(" SELECT ");
                     strQuery.Append("'" + Guid.NewGuid() + "',");
                       strQuery.Append("'" + (GrdvewBnkDetls.Rows[i].Cells[1].FindControl("ddlBnkNme") as DropDownList).SelectedValue + "',");
                       strQuery.Append("'" + (GrdvewBnkDetls.Rows[i].Cells[2].FindControl("ddlBrnch") as DropDownList).SelectedValue + "',");
                       strQuery.Append("'" + entbnkObj.PartyUoid + "',");
                       strQuery.Append("'" + (GrdvewBnkDetls.Rows[i].Cells[3].FindControl("ddlAccnt") as DropDownList).SelectedValue + "',");
                       strQuery.Append("'" + Guid.NewGuid() + "',");
                       strQuery.Append("'" + clsCommon.convertDate(DateTime.Now.ToString("dd/MM/yyyy")) + "',");
                       strQuery.Append("0");
                       strQuery.Append(" UNION ALL ");

               }
               strQuerys = strQuery.ToString();
           }

           else
           {
               strQuerys = string.Empty;
           }

           if (strQuerys != string.Empty)
           {
               int x = strQuery.ToString().Length;
               strQuerys = strQuerys.Remove(strQuery.ToString().Length - 11, 11);

           }

           return strQuerys;
       }
Posted
Updated 7-Oct-12 22:46pm
v2

1 solution

r u talking about ddlBank or ddlAccount or both..?
Please reply me..

And FYI when you assign a datasource or bind the ddl, a new set of data is populatd into the ddl. So your previously selectdvalue is gone. u can maintain ur selectd value in a hiddenfield or a viewstate so that you can restore it back after the databind() of that particular ddl.
Thanks
 
Share this answer
 
Comments
rosren 8-Oct-12 7:57am    
both
rosren 8-Oct-12 8:00am    
I want code pleasee help me ..thnksss

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900