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: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>
public void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
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");
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].Cells[3].Text.ToString()) == 7)
{
if (Convert.ToInt32(HirearchyGv.Rows[rowindex].Cells[0].Text.ToString()) == 10)
{
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");
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
{
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");
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()) == 8)
{
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);
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)
{
MemberNameCmbox.Items.Clear();
ViewState["BranchCode"] = str2;
BranchCodeTxt.Text = str2;
dt = BLGlobalHierachy.GetCROInHierarchy(str1, str2);
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);
}
else
{
if (ViewState["CRO"] == null)
{
ViewState["CRO"] = "";
}
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);
}
}
else
{
if (Convert.ToInt32(HirearchyGv.Rows[rowindex].Cells[3].Text.ToString()) == 9)
{
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);
}
}