Select a row when textbox clicked

5 posts, 1 answers
  1. Iosu Buenetxea
    Iosu Buenetxea avatar
    91 posts
    Member since:
    Jan 2008

    Posted 18 Sep 2008 Link to this post

    Hello

    I'm using some templates in my radGrid, in this templates I have a Textbox inside, when I click in the row I throw the SelectedIndexChanged method, but when I click in the textbox I want to select this row and throw the selectedIndexChanged method also.

    How can I do this?

    Thanks.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Sep 2008 Link to this post

    Hi Juan,

    Try the following code snippet to achieve the desired scenario.

    ASPX:
    <telerik:GridTemplateColumn UniqueName="TempCol" HeaderText="TempCol" > 
             <ItemTemplate> 
               <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
             </ItemTemplate> 
        </telerik:GridTemplateColumn> 

    CS:
     protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                int index = item.ItemIndex; 
                TextBox txtbx = (TextBox)item["TempCol"].FindControl("TextBox1"); 
                txtbx.Attributes.Add("OnClick", "return Select('" + index + "');"); 
            } 
             
        } 


    JS:
     <script  language="javascript" type="text/javascript"
        function Select(index) 
        { 
         
        var grid = $find("<%= RadGrid1.ClientID %>"); 
        grid.MasterTableView.get_dataItems()[index].set_selected(true); 
        __doPostBack("<%=RadGrid1.ClientID %>") 
        } 
      <script /> 


    Cheers
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Iosu Buenetxea
    Iosu Buenetxea avatar
    91 posts
    Member since:
    Jan 2008

    Posted 19 Sep 2008 Link to this post

    Hello Shinu !!

    This is a solution but when I select another row the radGrid has selected more than one row, and I want to have only one row selected.

    How can I do this?
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Sep 2008 Link to this post

    Hi Juan,

    One suggestion will be to clear the all the selected items in the client event before selecting the row.

    JS:
    <script  language="javascript" type="text/javascript"
        function Select(index) 
        { 
         
        var grid = $find("<%= RadGrid1.ClientID %>"); 
        grid.get_masterTableView().clearSelectedItems(); 
        grid.MasterTableView.get_dataItems()[index].set_selected(true); 
         
        } 
    <Script/> 

    Hope this helps..
    Princy.
  6. Iosu Buenetxea
    Iosu Buenetxea avatar
    91 posts
    Member since:
    Jan 2008

    Posted 19 Sep 2008 Link to this post

    Hello Princy

    This is the answer, Thanks.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017