Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a requirement like in my application for each and every form.

I have a hierarchy like.

Head office
,Zonal office
,Regional office
,Area Office
,Unit Office
and Branch Office

After selection of head office zonal has to bind, on selection of Zonal, regional office as to bind and same for all hierarchy. But in some case area and unit will not present.

So directly after regional branch office has to come.

For this I did with drop down placing in grid view control, it working fine for dynamic set of drop downs but I have an explicit requirement.

Under each branch, Members will be registered. In some from customer asking for if he enters member id the hierarchy has to bind i.e from bottom to top it as to bind on member id entered .

How can I do this any way for my both problems.
ASP.NET
<asp:GridView ID="HirearchyGv" runat="server" AutoGenerateColumns="false" Width="100%"
                                                                    CellPadding="3" OnRowDataBound="HirearchyGv_RowDataBound" OnPreRender="HirearchyGv_PreRender">
                                                                    <Columns>
                                                                        <asp:BoundField DataField="HIERARCHY_ID" />
                                                                        <asp:BoundField DataField="HIERARCHY_NAME" ItemStyle-Width="185px" />
                                                                        <asp:TemplateField ItemStyle-HorizontalAlign="Left">
                                                                            <ItemTemplate>
                                                                                <asp:DropDownList ID="ddl1" runat="server" TabIndex="2" AutoPostBack="True" OnSelectedIndexChanged="ddl1_SelectedIndexChanged"
                                                                                    CssClass="mandatory-comobox170">
                                                                                </asp:DropDownList>
                                                                            </ItemTemplate>
                                                                            <ItemStyle HorizontalAlign="Left"></ItemStyle>
                                                                        </asp:TemplateField>
                                                                        <asp:BoundField DataField="HIERARCHY_ORDER" />
                                                                        <asp:BoundField DataField="DB_TABLE_NAME" />
                                                                    </Columns>
                                                                </asp:GridView>


C#
public void ddl1_SelectedIndexChanged(object sender, EventArgs e)
      {
          // int count = DataList1.Items.Count;
          try
          {
              int count = HirearchyGv.Rows.Count;
              int rowindex = -1;

              GridViewRow gr = (GridViewRow)((DataControlFieldCell)((DropDownList)sender).Parent).Parent;
              DropDownList d1 = (DropDownList)gr.FindControl("ddl1");

              rowindex = gr.RowIndex;
              for (int i = rowindex; i < count - 1; i++)
              {
                  DropDownList d2 = (DropDownList)HirearchyGv.Rows[i + 1].FindControl("ddl1");
                  //(DropDownList)gr.FindControl("ddl1");
                  string str1 = HirearchyGv.Rows[rowindex + 1].Cells[4].Text.ToString().Trim();
                  d2.Items.Clear();
                  d2.DataSource = null;
                  d2.DataBind();
                  d2.Items.Insert(0, "--Select--");
                  d2.BackColor = System.Drawing.Color.White;
                  ClearMemberFields();
                  MemberIdTxt.Text = "";

                  MemberNameCmbox.Items.Clear();
                  MemberNameCmbox.Items.Insert(0, "--Select--");
                  MemberNameCmbox.SelectedIndex = 0;

              }
              if (count - 1 > rowindex)
              {
                  DataTable dt = new DataTable();
                  string str1 = HirearchyGv.Rows[rowindex + 1].Cells[4].Text.ToString().Trim();
                  string str2 = d1.SelectedValue;
                  //if (Convert.ToInt32(HirearchyGv.Rows[rowindex +1 ].Cells[3].Text.ToString()) == 7)
                  if (Convert.ToInt32(HirearchyGv.Rows[rowindex].Cells[3].Text.ToString()) == 7)
                  {
                      if (Convert.ToInt32(HirearchyGv.Rows[rowindex].Cells[0].Text.ToString()) == 10)
                      {
                          // Binding Villages
                          ViewState["CRO"] = str2;
                          dt = BLGlobalHierachy.GetAfterMembermaping(str1, ViewState["CRO"].ToString(), ViewState["BranchCode"].ToString(), HirearchyGv.Rows[rowindex].Cells[0].Text.ToString(), LoantypesDdl.SelectedValue);
                          DropDownList d2 = (DropDownList)HirearchyGv.Rows[rowindex + 1].FindControl("ddl1");
                          //(DropDownList)gr.FindControl("ddl1");
                          d2.DataSource = dt;
                          d2.DataTextField = "CURRENT_NAME";
                          d2.DataValueField = "CURRENT_ID";
                          d2.DataBind();
                          d2.Items.Insert(0, "--Select--");
                          d2.BackColor = System.Drawing.Color.FromArgb(191, 246, 181);

                      }
                      else
                      {
                          //Bindings Centers
                          ViewState["VillageCode"] = str2;
                          dt = BLGlobalHierachy.GetAfterMembermaping(str1, ViewState["CRO"].ToString(), str2, HirearchyGv.Rows[rowindex].Cells[0].Text.ToString(), LoantypesDdl.SelectedValue);
                          DropDownList d2 = (DropDownList)HirearchyGv.Rows[rowindex + 1].FindControl("ddl1");
                          //(DropDownList)gr.FindControl("ddl1");
                          d2.DataSource = dt;
                          d2.DataTextField = "CURRENT_NAME";
                          d2.DataValueField = "CURRENT_ID";
                          d2.DataBind();
                          d2.Items.Insert(0, "--Select--");
                          d2.BackColor = System.Drawing.Color.FromArgb(191, 246, 181);

                          //Bind Village Members


                      }
                  }
                  else if (Convert.ToInt32(HirearchyGv.Rows[rowindex].Cells[3].Text.ToString()) == 8)
                  {
                      //Binding Groups
                      ViewState["CenterCode"] = str2;
                      dt = BLGlobalHierachy.GetAfterMembermaping(str1, ViewState["CRO"].ToString(), str2, HirearchyGv.Rows[rowindex].Cells[0].Text.ToString(), LoantypesDdl.SelectedValue);
                      DropDownList d2 = (DropDownList)HirearchyGv.Rows[rowindex + 1].FindControl("ddl1");

                      d2.DataSource = dt;
                      d2.DataTextField = "CURRENT_NAME";
                      d2.DataValueField = "CURRENT_ID";
                      d2.DataBind();
                      d2.Items.Insert(0, "--Select--");
                      d2.BackColor = System.Drawing.Color.FromArgb(191, 246, 181);

                      //Bind Center Members

                      if (LoantypesDdl.SelectedValue == "2" || LoantypesDdl.SelectedValue == "1")
                      {

                          string ParentID = ViewState["CenterCode"].ToString().Trim();
                          int LoanTypeId = Convert.ToInt32(LoantypesDdl.SelectedValue);
                          string CroName = ViewState["CRO"].ToString().Trim();
                          DataTable dt1 = new DataTable();
                          dt1 = BLGlobalHierachy.GetCenterMemers(ParentID, LoanTypeId, CroName);
                          MemberNameCmbox.DataSource = dt1;
                          MemberNameCmbox.DataTextField = "MEMBER_NAME";
                          MemberNameCmbox.DataValueField = "MEMBER_ID";
                          MemberNameCmbox.DataBind();
                          MemberNameCmbox.Items.Insert(0, "--select--");
                      }


                  }
                  else if (Convert.ToInt32(HirearchyGv.Rows[rowindex].Cells[3].Text.ToString()) == 6)
                  {
                      //Binding CRO
                      MemberNameCmbox.Items.Clear();
                      ViewState["BranchCode"] = str2;
                      BranchCodeTxt.Text = str2;
                      dt = BLGlobalHierachy.GetCROInHierarchy(str1, str2);
                      DropDownList d2 = (DropDownList)HirearchyGv.Rows[rowindex + 1].FindControl("ddl1");
                      //(DropDownList)gr.FindControl("ddl1");
                      d2.DataSource = dt;
                      d2.DataTextField = "CURRENT_NAME";
                      d2.DataValueField = "CURRENT_ID";
                      d2.DataBind();
                      d2.Items.Insert(0, "--Select--");
                      d2.BackColor = System.Drawing.Color.FromArgb(191, 246, 181);

                  }
                  else
                  {
                      if (ViewState["CRO"] == null)
                      {
                          ViewState["CRO"] = "";
                      }
                      //binding the Hirearchy upto branch
                      dt = BLGlobalHierachy.GetAfterMembermaping(str1, ViewState["CRO"].ToString(), str2, HirearchyGv.Rows[rowindex].Cells[0].Text.ToString(), LoantypesDdl.SelectedValue);
                      DropDownList d2 = (DropDownList)HirearchyGv.Rows[rowindex + 1].FindControl("ddl1");
                      //(DropDownList)gr.FindControl("ddl1");
                      d2.DataSource = dt;
                      d2.DataTextField = "CURRENT_NAME";
                      d2.DataValueField = "CURRENT_ID";
                      d2.DataBind();
                      d2.Items.Insert(0, "--Select--");
                      d2.BackColor = System.Drawing.Color.FromArgb(191, 246, 181);
                  }


              }
              else
              {
                  if (Convert.ToInt32(HirearchyGv.Rows[rowindex].Cells[3].Text.ToString()) == 9)
                  {
                      // Bind Group Members

                      if (LoantypesDdl.SelectedValue == "1" || LoantypesDdl.SelectedValue == "2")
                      {
                          string ParentID = ViewState["CenterCode"].ToString().Trim();
                          string CurrentID = d1.SelectedValue;
                          ViewState["CurrentId"] = CurrentID.ToString().Trim();
                          int LoanTypeId = Convert.ToInt32(LoantypesDdl.SelectedValue);
                          string CroName = ViewState["CRO"].ToString().Trim();
                          DataTable dt1 = new DataTable();
                          dt1 = BLGlobalHierachy.GetGroupMemersDis(ParentID, CurrentID, LoanTypeId, CroName);
                          MemberNameCmbox.DataSource = dt1;
                          MemberNameCmbox.DataTextField = "MEMBER_NAME";
                          MemberNameCmbox.DataValueField = "MEMBER_ID";
                          MemberNameCmbox.DataBind();
                          MemberNameCmbox.Items.Insert(0, "--select--");
                          LoadAllGroupLoans();
                      }
                      if (LoantypesDdl.SelectedValue == "4")
                      {
                          string ParentID = ViewState["VillageCode"].ToString().Trim();
                          string CurrentID = d1.SelectedValue;
                          ViewState["CurrentId"] = CurrentID.ToString().Trim();
                          int LoanTypeId = Convert.ToInt32(LoantypesDdl.SelectedValue);
                          string CroName = ViewState["CRO"].ToString().Trim();
                          DataTable dt1 = new DataTable();
                          dt1 = BLGlobalHierachy.GetGroupMemersDis(ParentID, CurrentID, LoanTypeId, CroName);
                          MemberNameCmbox.DataSource = dt1;
                          MemberNameCmbox.DataTextField = "MEMBER_NAME";
                          MemberNameCmbox.DataValueField = "MEMBER_ID";
                          MemberNameCmbox.DataBind();
                          MemberNameCmbox.Items.Insert(0, "--select--");
                          LoadAllGroupLoans();
                      }


                  }
                  if (Convert.ToInt32(HirearchyGv.Rows[rowindex].Cells[3].Text.ToString()) == 7)
                  {
                      if (LoantypesDdl.SelectedValue == "3")
                      {
                          string ParentID = ViewState["BranchCode"].ToString().Trim();
                          string CurrentID = d1.SelectedValue;
                          ViewState["CurrentId"] = CurrentID.ToString().Trim();
                          string CroName = ViewState["CRO"].ToString().Trim();
                          int LoanTypeId = Convert.ToInt32(LoantypesDdl.SelectedValue);
                          DataTable dt1 = new DataTable();
                          dt1 = BLGlobalHierachy.GetVillagememersDis(ParentID, CurrentID, CroName, LoanTypeId);
                          MemberNameCmbox.DataSource = dt1;
                          MemberNameCmbox.DataTextField = "MEMBER_NAME";
                          MemberNameCmbox.DataValueField = "MEMBER_ID";
                          MemberNameCmbox.DataBind();
                          MemberNameCmbox.Items.Insert(0, "--select--");
                          LoadAllGroupLoans();
                      }

                  }
              }

          }
          catch (Exception ex)
          {
              log.Error(ex.Message, ex);
          }


      }
Posted
Updated 13-Dec-11 19:49pm
v3
Comments
Balakrishnan Dhinakaran 14-Dec-11 0:32am    
you want to display nested accordion menu which drives values from sql server am I right?
karthikkushala 14-Dec-11 0:47am    
no, not accordion menu . dynamic drop down list and revere binding
Code 89 14-Dec-11 0:33am    
post your code..
karthikkushala 14-Dec-11 0:48am    
i added asp and cs code ,

1 solution

First, After regional bind area, unit and branch in one time and if any one not have data then it will show only select

Second, based on member id fetch branch, after that based on branch fetch unit after that area if unit or area not have items then fetch regional and set selected value to saved value in database based on that membership id and so on.
 
Share this answer
 
Comments
karthikkushala 14-Dec-11 0:53am    
ya what u said is correct , but i have a drop down before grid view , i will work as conditional ,like if i select 1 it shows only 3 hierarchies , if i select 2 it shows all.
the functionality working fine but , get after entering member id it how can i bind in revers order for drop down which are in gridview with out any event

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