This is a migrated thread and some comments may be shown as answers.

radgrid rows not selected on textbox click

4 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allen
Top achievements
Rank 1
Allen asked on 26 Oct 2012, 04:27 AM
Hi
     I have a radgrid in which iam using template columns. I am selecting radgrid rows on clicking a row. But when i click on the textbox in templatecolumn, the row is not getting selected.Please help me out.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Oct 2012, 04:42 AM
Hi,

Please try the following code snippet to select a row on TextBox click.

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

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.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 + "');");
        }
}


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

Thanks,
Princy.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Oct 2012, 05:10 AM
Hello,

By mistake Princy forget to add C# code.

So please try with updated code.

<telerik:GridTemplateColumn>
    <ItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </ItemTemplate>
</telerik:GridTemplateColumn>


  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
         
        if (e.Item is GridDataItem)
        {
            TextBox TextBox1 = e.Item.FindControl("TextBox1") as TextBox;
            TextBox1.Attributes.Add("onclick", "Select('"+e.Item.ItemIndex+"');");
        }
}
function Select(index) {
               var grid = $find("<%= RadGrid1.ClientID %>");
               grid.MasterTableView.get_dataItems()[index].set_selected(true);
           }


Thanks,
Jayesh Goyani
0
Ankush
Top achievements
Rank 1
answered on 06 Dec 2014, 07:44 PM
Hi Jayesh/Princy/All,

I am facing an issue. Row is getting highlighted when I click on the text in the row but when I click on the empty space in the row, row is not getting highlighted. 

It seems no event is firing on clicking on empty space in the row(screenshot attached). Please help !

Thanks,
Ankush
0
Eyup
Telerik team
answered on 11 Dec 2014, 09:18 AM
Hi Ankush,

Can you please elaborate on your specific configuration? The rows should be selected as expected on cell click:
http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/selecting/row-selection/defaultcs.aspx

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Allen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Ankush
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or