Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
have a dropdownlist control in gridview which shows the product version . I want when i select the version from dropdownlisst the price corresponding to it from table comes in the price column .

my cs code is


C#
private void BindProductData()
    {
      DataManager myData = new DataManager(DbFunctions.GetConnectionString());
      MySqlConnection myPConn = myData.GetPooledConnection(new MySqlConnection());
      DataSet productTable = new DataSet();
      MySqlDataAdapter sAdapter;

      sAdapter = new MySqlDataAdapter("select * from productmast P Inner join productdetail V on P.productid=V.productid Inner join userpermission U on P.productid=U.productid where adminuserid = " + Session["AdminUserId"].ToString() + "", myPConn);
      sAdapter.Fill(productTable, "productmast");
      if (productTable.Tables["productmast"].Rows.Count == 0)
      {
        LabelError.InnerText = "No Rows Found";
      }
      else
      {
        Products.DataSource = productTable;
      }
      Products.DataBind();
      myData.CloseConnection(myPConn);
    }

    protected void Products_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
        DataManager myData = new DataManager(DbFunctions.GetConnectionString());
        MySqlConnection myPConn = myData.GetPooledConnection(new MySqlConnection());

        string strProductId = ((DataRowView)(e.Row.DataItem)).Row[0].ToString();

        //Setup the Select Checkbox

        CheckBox chkSelect = (CheckBox)e.Row.FindControl("chkSelect");
        if (chkSelect != null)
        {
          chkSelect.Checked = ShoppingCart.IsProductSelected((DataTable)Session["Admin_Order"], "productid", strProductId);
        }

        //Setup the Select Checkbox

        CheckBox chkEvalVersion = (CheckBox)e.Row.FindControl("ChkEvalVersion");
        if (chkEvalVersion != null)
        {
          chkEvalVersion.Checked = ShoppingCart.IsEvalVersion(Session["Admin_Order"], "productid", strProductId);
        }

        //Setup the version DropDownList
        DropDownList ddlVersion = (DropDownList)e.Row.FindControl("ddlVersion");

        if (ddlVersion != null)
        {
          MySqlDataReader productReader = null;
          myData.GetDataReader("productdetail", "productdetailid, version",
                   "productid = " + TextUtilities.ToSql(strProductId, "N"), null,
                   "productdetailid",
                   ref productReader, myPConn);

          ddlVersion.DataSource = productReader;
          ddlVersion.DataBind();
          ddlVersion.SelectedValue = ShoppingCart.GetSelectedProductDetailId((DataTable)Session["Admin_Order"], "productid", strProductId);
        }
        myData.CloseConnection(myPConn);
      }
    }
Posted
Updated 1-Nov-11 20:56pm
v2

1 solution

For Drop down list control check u added
AutoPostBack = "true"
or not.

If not the code in the .aspx.cs page is not hit when u change the item in the first drop down list.
 
Share this answer
 
Comments
Vimalrashamra 2-Nov-11 3:07am    
i already done that
sabbi26 2-Nov-11 3:13am    
are u wrote the code for ddlfirst__SelectedIndexChanged event in ur aspx.cs file.
if u wrote already please post the code
Vimalrashamra 2-Nov-11 3:24am    
no i didnt wrote
sabbi26 2-Nov-11 3:25am    
than write that method.In that get the values and assign to the second drop down list.
I hope it will fix ur problem

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