Click here to Skip to main content
15,886,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey Guys,
I have combo box in my application and it shows name of customer from the database. Now, I want to fetch other data related to that customer and display on application. the data is like customer address, mobile no, city etc.
Posted
Updated 22-Dec-11 22:55pm
v2
Comments
koolprasad2003 23-Dec-11 4:58am    
what is the problem then ?

1 solution

Try this,


ASP.NET
<asp:DropDownList AutoPostBack="true" ID="dd1" runat="server" OnSelectedIndexChanged="dd_select_changed">

       </asp:DropDownList>
       <asp:DropDownList ID="dd2" runat="server">
       </asp:DropDownList>
       <asp:Label ID="label1" runat="server"></asp:Label>
       <asp:Label ID="label2" runat="server"></asp:Label>
       <asp:Label ID="label3" runat="server"></asp:Label>


C#
 protected void Page_Load(object sender, EventArgs e)
    {
        connection();
        string sql = "select * from Customer ";
        cmd = new SqlCommand(sql, conn);
        da = new SqlDataAdapter(cmd);
        da.Fill(ds);

           
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dd1.DataSource = ds.Tables[0];
                dd1.DataBind();
                dd1.DataTextField = "CustomerName";//Colmn  name of custmer name in database table
                dd1.DataValueField = "CustomerId";//Colmn  name of custmer name in database table
                Label1.Text = ds.Tables[0].Rows[i]["CustomerAddress"].ToString();
            }
   }

 public void connection()
    {
        string sqlcon = System.Configuration.ConfigurationManager.AppSettings["conn"];
        conn=new SqlConnection(sqlcon);
        conn.Open();
    }

protected void dd_select_changed(object sender, EventArgs e)
    {
        connection();
        string sql = "select * from Customer where CustomerId='"+ Convert.ToInt32(dd1.SelectedItem.Value.ToString()) + "' ";
        cmd = new SqlCommand(sql, conn);
        da = new SqlDataAdapter(cmd);
        da.Fill(ds);
            Label1.Text = ds.Tables[0].Rows[0]["CustomerAddress"].ToString();
            Label2.Text = ds.Tables[0].Rows[0]["CustomerMobile"].ToString();
            Label3.Text = ds.Tables[0].Rows[0]["CustomerCity"].ToString();
    }
 
Share this answer
 
v2
Comments
Laxman Auti 23-Dec-11 4:57am    
Instead of mapping record to the customer name, i would recommend to map the record to customer id (combo box value field) which is generally unique. And, afterwords use that id to fetch other details from the database on demand.
Shobana16 23-Dec-11 5:11am    
Try the first solution now.

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