You must Sign In to post a response.
  • Category: .NET

    Binded data to datagridview of material detail and I added one combo box it contains list

    Binded data to datagridview of material detail and I added one combo box it contains list of shapes when I select shape at combobox selected shapes material details only should display at binded datagridview
  • #749980
    For this requirement you have to pass combobox selected value to sql query like this.
    select * from tableName shapes=@shapes

    so your complete code is.

    SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionstringName"].ConnectionString);
    SqlCommand cmd = new SqlCommand("select * from tableName shapes=@shapes", cn);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    GridView1.DataSource = dt;

    Nirav Prabtani (Senior Web Developer)
    Email :
    blog :

  • #749982
    Try this code

    protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
    SqlDataAdapter sqlAdp = new SqlDataAdapter("Select id,Product from Product ", conn);
    DataTable dt = new DataTable();
    DropDownList1.DataTextField = "Product";
    DropDownList1.DataValueField = "id";
    DropDownList1.DataSource = dt;
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    SqlDataAdapter sqlAdp = new SqlDataAdapter("Select * from Product1 where Product1='" + DropDownList1.SelectedItem.Text + "' ", conn);
    DataTable dt = new DataTable();
    Grd1.DataSource = dt;
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
    <asp:GridView ID="Grd1" runat="server">

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #749986
    When I select shape at combobox , is there any technic at gridview to display data related to selected shape without going back to sql database

  • #750000
    yes it is possible as your application is windows based application the data in the datatable is not lost on postback(when you select different item in the combobox). So in this case you can write below code to select few records of the datatable based on the value selected in the combobox and then bind this datatable to the datagridview.

    DataTable dt = new DataTable();

    assuming that your datatable has single column: Item as shown below:
    dataGridView1.DataSource = dt;

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    DataView dv = dt.DefaultView;
    dv.RowFilter = "Item = "+"'" + comboBox1.SelectedItem + "'";

    dataGridView1.DataSource = dv;

    in the comboBox1_SelectedIndexChanged event we are applying row filter to the dataview of the datatable and assigning this dataview with filtered records to the datasource property of the datagridview.

    Please let me know if you have any doubts in this code and it works fine.

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #750011
    Madam Priya Jain, how filter by multiple combo box I added one combo box for shape select and I want add 3 more combo box of material catagory, material sub catagory and material name

  • #750013
    Hi Rajanikant,

    Please clarify as whether your another combo box is cascaded. I mean to say whether you are displaying values of other depending on the 1st,2nd or any other combo box.
    If yes, then you can achieve this like below-
    private void comboBox1_Selectionchanged(object sender, SelectionchangedEventArgs e)
    aA = comboBox1.SelectedItem.ToString();

    Ashutosh Jha

  • #750017
    Binded datagridview at page load and when I select shape fromm combobox then datagridview should filter for selected shape andif I select material catagory from second combobox thrn datagridview should filter by filter by combobox1 and combobox2 totally I added 4 combo box

  • #750022
    Please write code in selected index change of every combobox and map it to a common method where you check the values in each combobox and filter the records as shown above in my code snippet, you can also write multiple filter for dataview of the datatable and then bind it to datagridview. Please try below sample code. Do it for all combobox. I have done for two.

    private void FilterData()
    DataView dv = dt.DefaultView;
    string filter1 = comboBox1.SelectedItem != null ? "Item = " + "'" + comboBox1.SelectedItem + "'" : "";
    string filter2 = comboBox2.SelectedItem != null ? "Material = " + "'" + comboBox2.SelectedItem + "'" : "";

    if (comboBox1.SelectedItem != null)
    dv.RowFilter = "Item = " + "'" + comboBox1.SelectedItem + "'";

    if(comboBox2.SelectedItem != null)
    dv.RowFilter = string.Join(" AND ",filter1,filter2);

    dataGridView1.DataSource = dv;

    private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #750073

    If you want to display the result based on ComboBox selction then OnSelectedIndexChanged event of ComboBox you should wrote below lines of code.

    protected void Cmb_OnSelectedIndexChanged(object sender, EventArgs e)
    DataSet ds=obj.Get_Data(cmb1.SelectedValue);

    you just pass the combobox selected value as a input parameter to achieve this.

    Hope this will help you to resolve your issue...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #750311
    Priya join madam below code giving error like "No overload for method 'Join' takes '3' arguments"
    Code : string.Join(" AND ",filter1,filter2);

  • Sign In to post your comments