using controlS to control a gridview


This question is probably posted but i did not bother to look at 10,000+ posts so i am sorry.
 I've seen the tutorial where he builds a dataset and uses a gridview and controls the gridview with the drop down list box. What i am trying to do is to control the gridview with 2 drop down list boxes. First select the Country you life in and then the State. I've looked at the grid view properties but couldn't find where i can add another parameter. Is it possible to control a grid view (or any form of displaying the information) with more than 1 controller?
Thank You.
 
0
peteradel
9/5/2007 6:59:07 AM
📁 asp.net.object-datasource
📃 16182 articles.
⭐ 0 followers.

💬 3 Replies
👁️‍🗨️ 1222 Views



You're quite correct.
This question (or one very similar to it) has been posted and answered before.

Regards

Dave
0
DMW
9/5/2007 8:20:53 AM

Hi,
It seems that you are trying to filter the data in GridView with two parameters, right?
If so, you may try to assign the rowfilter property of DataView with corresponding expression, filter the data in your DataSet. See the following sample:
DataSet myds = new DataSet();
    SqlDataAdapter adpt = null;
    protected void Page_Load(object sender, EventArgs e)
    {
            string conn = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
            SqlConnection myconn = new SqlConnection(conn);
            string sql = "select * from Categories";
            adpt = new SqlDataAdapter(sql, conn);

            adpt.Fill(this.myds); //  Fill the data into dataset.
            if (!IsPostBack)
            {
            bind(this.myds.Tables[0].DefaultView); // Bind the GridView.
            }
    }
    public void bind(DataView dv) {
        this.GridView1.DataSource = dv;
        this.GridView1.DataBind();
    }

            
/// This is the handler for the filter event.
    protected void Button1_Click(object sender, EventArgs e)
    {
        string ar1 = this.DropDownList1.SelectedValue;
        string ar2 = this.DropDownList2.SelectedValue;
        this.myds.Tables[0].DefaultView.RowFilter = "CategoryID='" + ar1 + "' and CategoryName='" + ar2 + "'";
        bind(myds.Tables[0].DefaultView); //  Rebind the GridView.
    }
 Hope that helps.

Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Nai
9/6/2007 9:15:38 AM

Thank You, that really helped!  Yes
 
0
peteradel
9/6/2007 4:47:46 PM
Reply: