You must Sign In to post a response.
  • Category: ASP.Net MVC

    Select the grid row when you click on enter from autocomplete textbox

    Hi,

    I grid will display with the check box from the database table. Now I need the autocomplete textbox for searching and if the user search for ex:- venkat and click on the enter the corresponding row in the grid should be checked.

    Any one suggest me how to achieve this.

    Regards,
    Venkat.
  • #766168
    Hi,

    I suspect the AutoComplete TextBox and button controls are outside the gridview, based on search you should check the checkbox inside gridview?

    If my understanding is correct then OnRowDataBound event of gridview customize your code as you need.

    Ex:

    Protected void Gv_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
    if(txtVal.Text!=string.Empty)
    {
    string cellVal=((Label)e.Row.FindControl("lblVal")).ToString();
    if(cellVal.ToUpper().ToString().Contains(txtVal.Text.ToUpper().ToString())
    {
    ((CheckBox)e.Row.FindControl("chkSel")).Checked=true;
    }
    }
    }
    }

    Protected Void bntClick(object sender, EventArgs e)
    {
    //rebind your grid
    }


    Hope this will helpful to you...

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

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #766174
    if you have successfully implement autocomplete textbox in gridview then, when user press enbter key in auto complete textbox you have to avoid the postback and select the row
    use below JQuery to prevent postback in enterkey press

    $(document).ready(function() {
    $(window).keydown(function(event){
    if(event.keyCode == 13) {
    event.preventDefault();
    return false;
    }
    });
    });

    check below link for more details
    http://www.codeproject.com/Articles/38579/Handling-the-Enter-key-pressed-in-a-GridView-s-row

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments