Hi,
I have set on my grid AllowMultiRowSelection="False".
My Problem is :
I have a Master Table and Detail Table,.
On my Details Table i have a Hyper link. When User click on that Hyperlink i am selecting Parent-row and Details Table Hyperlink Clicked Row. But the Problem is, if i click on any other hyperlink it's selecting multiple rows even if i set AllowMultiRowSelection="False"
here is my code
ASPX:
CS
JavaScript
I have set on my grid AllowMultiRowSelection="False".
My Problem is :
I have a Master Table and Detail Table,.
On my Details Table i have a Hyper link. When User click on that Hyperlink i am selecting Parent-row and Details Table Hyperlink Clicked Row. But the Problem is, if i click on any other hyperlink it's selecting multiple rows even if i set AllowMultiRowSelection="False"
here is my code
ASPX:
<
telerik:GridTemplateColumn
UniqueName
=
"Tempcol"
>
<
ItemTemplate
>
<
asp:HyperLink
ID
=
"HyperLink1"
runat
=
"server"
Text
=
"ClickMe"
></
asp:HyperLink
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
CS
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item.OwnerTableView.Name == "DetailTable" && e.Item is GridDataItem )
{
HyperLink hLink = (HyperLink)item.FindControl("HyperLink1");
hyplnk.Attributes.Add("OnClick", "return OpenLink('"+ item1.ItemIndex +"');");
}
}
JavaScript
function OpenLink(indx)
{
var RadGrid2 = $find("<%= RadGrid2.ClientID %>");
RadGrid2.get_masterTableView().get_dataItems()[indx].set_selected("true");
}
7 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 02 Jan 2014, 06:47 AM
Hi Venkata,
I guess on the child roes HyperLink click, you wan to set the parent row to be selected when AllowMultiRowSelection="false". Please try the following code snippet:
C#:
JS:
Thanks,
Princy
I guess on the child roes HyperLink click, you wan to set the parent row to be selected when AllowMultiRowSelection="false". Please try the following code snippet:
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item.OwnerTableView.Name ==
"DetailTable"
&& e.Item
is
GridDataItem)
{
GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;
//To access the parentItem
string
parentindex = parentItem.ItemIndex.ToString();
GridDataItem item = (GridDataItem)e.Item;
HyperLink lnk = (HyperLink)item.FindControl(
"HyperLink1"
);
lnk.Attributes.Add(
"OnClick"
,
"return OpenLink('"
+ parentindex +
"');"
);
}
}
JS:
function
OpenLink(indx) {
var
masterTable = $find(
"<%=RadGrid2.ClientID%>"
).get_masterTableView();
masterTable.selectItem(indx);
}
Thanks,
Princy
0

Venkata
Top achievements
Rank 1
answered on 02 Jan 2014, 03:20 PM
Hi Princy,
Thank you for your reply.
Sorry ..Your misunderstood my question/requirement
I want to select Both Parent and Child rows when HyperLink click
But it's not working..
here is my code:
JS:
var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();
masterTable.selectItem(parentindex);
Thank you for your reply.
Sorry ..Your misunderstood my question/requirement
I want to select Both Parent and Child rows when HyperLink click
But it's not working..
here is my code:
protected void radGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item.OwnerTableView.Name == "DetailsTable" && e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
HyperLink hLink = (HyperLink)item.FindControl("HyperLink1");
string strNavigateUrl = "www.google.com"
hLink.NavigateUrl = strNavigateUrl;
hLink.Attributes.Add("onclick", "return OpenLink('" + item.OwnerTableView.ParentItem.ItemIndex + "', '" + item.ItemIndex + "');");
}
}
JS:
function OpenLink(parentindex, childindex)
{
var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();
masterTable.selectItem(parentindex);
var detailTable = $find("<%= RadGrid1.ClientID %>").get_detailTables()[0];
detailTable.selectItem(childindex);
}
detailTable.selectItem(childindex);
}
0

Venkata
Top achievements
Rank 1
answered on 03 Jan 2014, 10:07 PM
any Idea why my code is not working(it's not selecting detail Table row)?
0
Hello,
When clicking on second hyperlink the item is selected, however the previous selection is not cleared. Because of this you have two rows set as selected.
In order to avoid this you could check if there are selected items in RadGrid and remove them from the SelectedItems collection. After this set the item where the hyperlink was clicked as selected.
Regards,
Viktor Tachev
Telerik
When clicking on second hyperlink the item is selected, however the previous selection is not cleared. Because of this you have two rows set as selected.
In order to avoid this you could check if there are selected items in RadGrid and remove them from the SelectedItems collection. After this set the item where the hyperlink was clicked as selected.
Regards,
Viktor Tachev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0

Princy
Top achievements
Rank 2
answered on 08 Jan 2014, 09:04 AM
Hi Venkata,
The way you have accesses the detail table is not getting the correct detailtable that was causing the issue. Please try the following code snippet:
JS:
Thanks,
Princy
The way you have accesses the detail table is not getting the correct detailtable that was causing the issue. Please try the following code snippet:
JS:
<script type=
"text/javascript"
>
function
OpenLink(parentindex, childindex) {
var
masterTable = $find(
"<%=RadGrid1.ClientID%>"
).get_masterTableView();
masterTable.selectItem(parentindex);
var
detailTable = $find(
"<%= RadGrid1.ClientID %>"
).get_detailTables()[parentindex];
detailTable.clearSelectedItems();
detailTable.get_dataItems()[childindex].set_selected(
true
);
}
</script>
Thanks,
Princy
0

Venkata
Top achievements
Rank 1
answered on 09 Jan 2014, 09:22 PM
Nope.. It's throwing an Error "undefined"
here what i did:
I have Expanded Parent Row 6 and clicked on hyperlink row 4
So technically
here what i did:
I have Expanded Parent Row 6 and clicked on hyperlink row 4
So technically
function
OpenLink(6, 4)
{
var
masterTable = $find(
"<%=RadGrid1.ClientID%>"
).get_masterTableView();
masterTable.selectItem(6);
-->
var
detailTable = $find(
"<%= RadGrid1.ClientID %>"
).get_detailTables()[6];
detailTable.clearSelectedItems();
detailTable.get_dataItems()[4].set_selected(
true
);
}
0
Hi Venkata,
In order for the selection to work in the described way you would need to have AllowMultiRowSelection property set to true. Additionally the client row selection should be enabled for RadGrid (set ClientSettings-Selecting-AllowRowSelect="true").
After this the OnClick handler for the HyperLink could be attached in ItemDataBound in a way similar to the one illustrated in previous posts. Note that the client id for the DetailTable is also passed as argument:
In the OnClick() function the previously selected items are deselected and the clicked item with its parent row is set as selected:
I am also attaching a sample project as illustration of the described approach.
Regards,
Viktor Tachev
Telerik
In order for the selection to work in the described way you would need to have AllowMultiRowSelection property set to true. Additionally the client row selection should be enabled for RadGrid (set ClientSettings-Selecting-AllowRowSelect="true").
After this the OnClick handler for the HyperLink could be attached in ItemDataBound in a way similar to the one illustrated in previous posts. Note that the client id for the DetailTable is also passed as argument:
protected
void
RadGrid3_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item.OwnerTableView.Name ==
"DetailTable"
&& e.Item
is
GridDataItem)
{
GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;
//To access the parentItem
string
parentindex = parentItem.ItemIndex.ToString();
string
childItemindex = e.Item.ItemIndex.ToString();
GridDataItem item = (GridDataItem)e.Item;
HyperLink lnk = (HyperLink)item.FindControl(
"HyperLink1"
);
lnk.Attributes.Add(
"OnClick"
,
"return OpenLink('"
+ parentindex +
"', '"
+ childItemindex +
"', '"
+ e.Item.OwnerTableView.ClientID +
"');"
);
}
}
In the OnClick() function the previously selected items are deselected and the clicked item with its parent row is set as selected:
function
OpenLink(parentindex, childindex, detailTableID) {
var
masterTable = $find(
"<%=RadGrid3.ClientID%>"
).get_masterTableView();
masterTable.clearSelectedItems();
masterTable.selectItem(masterTable.get_dataItems()[parentindex].get_element());
//clear selection from other detail tables
var
detailTables = $find(
"<%= RadGrid3.ClientID %>"
).get_detailTables();
for
(
var
i = 0; i < detailTables.length; i++) {
detailTables[i].clearSelectedItems();
}
var
detailTable = $find(detailTableID);
detailTable.clearSelectedItems();
detailTable.selectItem(detailTable.get_dataItems()[childindex].get_element());
}
I am also attaching a sample project as illustration of the described approach.
Regards,
Viktor Tachev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.