Click here to Skip to main content
15,886,069 members

i have 3 dropdownlist in gridview

rosren asked:

Open original thread
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;
       }
Tags: C#, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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