How to select a gridviewrow based on textbox value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • benwizzle
    New Member
    • May 2010
    • 72

    #1

    How to select a gridviewrow based on textbox value

    So basically I have a gridview that is selectable. Below it I have a dropdownlist and a textbox. The dropdownlist has the options for each column in the row(I am using an ajax autocomplete extender that checks for related values in the textbox based of which dropdownlist value is selected.) I want to take that a step further and see if I can select a row based on what is in the textbox on the textchanged event. Right now im playing around with using a datatable and then filling a string[] of whatever column the dropdownlist is selected on. And then im thinking about using something that will check the string array and select the first gridview row based on what is in the textbox. Am I going about this the right way? This is what I have so far.
    Code:
    protected void txtFilter_TextChanged(object sender, EventArgs e)
        {
            
            DataTable dt;
            SqlCommand cmd = new SqlCommand("SELECT * FROM General", csbg2);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            
    
            dt = fillDatatable(cmd, da);
            
            string[] items = new string[dt.Rows.Count];
    
            switch (ddlEducation.SelectedValue)
            {
                case "SSN":
                    int i = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        items.SetValue(dr["SSN"].ToString(), i);
                        i++;
                    }
                case "FName":
                    int i = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        items.SetValue(dr["FName"].ToString(), i);
                        i++;
                    }
                case "LName":
                    int i = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        items.SetValue(dr["LName"].ToString(), i);
                        i++;
                    }
    
               
    
            }//end switch
    
    
        }// end txtfilter_TextChanged
  • benwizzle
    New Member
    • May 2010
    • 72

    #2
    I was able to get this to work. No help needed now.

    Comment

    Working...