Multiple ComboBox Selected indexChanged Not getting Values

Posted by Shijohnjoseph under C# on 11/19/2011 | Points: 10 | Views : 1923 | Status : [Member] | Replies : 1
Hi Sir,
1) i have two combobox named ComboTravelAgentLoc , ComboTravelAgentName,
2) on Pageload i have to bind AgentLocation from DataBase in that dataset i have inserted the default value "--Select--",
3) on SelectedIndexChanged i have to bind TravelAgentName from database with related to the location which selected !...,
4) Here i am getting the problem 1st time while checking LocationSelectionChanged Event its getting a value and moving control to fill agent
Name here its my problem while binding values to agentName its automatically going to selectedindexChanged event of ComboTravelAgentName
here my condition brokes up and gettig my code to an infinite loop
this is my probelm !..
please anybody help me thanks!..
below my code

"Personality has the power to open many doors, but character must keep them open"


Responses

Posted by: Shijohnjoseph on: 11/19/2011 [Member] Starter | Points: 25

Up
0
Down

public void FillTravelAgentLocation()
{
DataSet dsTAgentLoc = new DataSet();
dsTAgentLoc = Obj_Class.UserInfo("select Agent_Location from Travel_Agents where Agent_Name<>'NONE'");
DataRow dr = dsTAgentLoc.Tables[0].NewRow();
dr[0] = "--Select--";
dsTAgentLoc.Tables[0].Rows.InsertAt(dr, 0);
comboTravelAgentLocation.DataSource = dsTAgentLoc.Tables[0];
comboTravelAgentLocation.DisplayMember = "Agent_Location";
comboTravelAgentLocation.SelectedIndex = 0;
comboTravelAgentLocation.ValueMember = "Agent_Location";

comboTravelAgentLocation.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.Never;
dsTAgentLoc.Dispose();

}

private void comboTravelAgentLocation_SelectedValueChanged(object sender, EventArgs e)
{
if (comboTravelAgentLocation.SelectedIndex!=0 )
{
int Index = comboTravelAgentLocation.SelectedIndex;
string AgentLoc = comboTravelAgentLocation.SelectedValue.ToString();
FillTravelAgentName(AgentLoc);
}
}
public void FillTravelAgentName(string AgentLoc)
{
DataSet dsAgentName = new DataSet();
if (AgentLoc == "")
{
dsAgentName = Obj_Class.UserInfo("select Agent_Name from Travel_Agents where Agent_Location<>'NONE'");
DataRow drAgentName = dsAgentName.Tables[0].NewRow();
drAgentName[0] = "--Select--";
dsAgentName.Tables[0].Rows.InsertAt(drAgentName, 0);
}
else
{
dsAgentName = Obj_Class.UserInfo("select Agent_Name from Travel_Agents where Agent_Location='" + AgentLoc + "'");
DataRow drAgentName = dsAgentName.Tables[0].NewRow();
drAgentName[0] = "--Select--";
dsAgentName.Tables[0].Rows.InsertAt(drAgentName, 0);
}

comboTravelAgentName.DataSource = dsAgentName.Tables[0];
comboTravelAgentName.DisplayMember = "Agent_Name";
comboTravelAgentName.ValueMember = "Agent_Name";
comboTravelAgentName.SelectedIndex = 0;
dsAgentName.Dispose();
}


private void comboTravelAgentName_SelectedValueChanged(object sender, EventArgs e)
{
if (comboTravelAgentLocation.SelectedIndex != 0 && comboTravelAgentName.SelectedIndex != 0)
{
string AgentLocation = comboTravelAgentLocation.SelectedValue.ToString();
string AgentName = comboTravelAgentName.SelectedValue.ToString();
DataSet dsAgentDtls = new DataSet();
dsAgentDtls = Obj_Class.UserInfo("select Agent_Code,Agent_Phone,Agent_Email,Agent_Web,Agent_Address from Travel_Agents where Agent_Name='" + AgentName + "' and Agent_Location='" + AgentLocation + "'");
if (dsAgentDtls.Tables[0].Rows.Count > 0)
{
txttAgentPhone.Text = dsAgentDtls.Tables[0].Rows[0][1].ToString();
txtAgentEmail.Text = dsAgentDtls.Tables[0].Rows[0][2].ToString();
txtAgentWeb.Text = dsAgentDtls.Tables[0].Rows[0][3].ToString();
txtAgentAddress.Text = dsAgentDtls.Tables[0].Rows[0][4].ToString();
}
}
}

"Personality has the power to open many doors, but character must keep them open"

Shijohnjoseph, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response