Hi!
I have added rad grid control on my page which allows the single selection for row. This is absolutely fine as per my requirment but.. I need to show radio buttons instead of check boxes. I think from user point of view, we always give radio buttons whenever there is a scenario for single selection and checkboxes for multiple selection. So in this case also I wanted the same, i tried to explore enough on this .. but I am unable to get the solution in teleric rad grid control api.
Do we have any workaround for this???
Please Reply ASAP
Thanks in Advance!
With Regards,
Fatima Khan
I have added rad grid control on my page which allows the single selection for row. This is absolutely fine as per my requirment but.. I need to show radio buttons instead of check boxes. I think from user point of view, we always give radio buttons whenever there is a scenario for single selection and checkboxes for multiple selection. So in this case also I wanted the same, i tried to explore enough on this .. but I am unable to get the solution in teleric rad grid control api.
Do we have any workaround for this???
Please Reply ASAP
Thanks in Advance!
With Regards,
Fatima Khan
2 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 12 Feb 2009, 10:20 AM
Hello Fatima,
Checkout the code library which uses radio button residing in ItemTemplate of RadGrid template column for selecting only single row at a time. Hope this will be helpful.
Single RadioButton check at a time with row selection
Thanks,
Shinu.
Checkout the code library which uses radio button residing in ItemTemplate of RadGrid template column for selecting only single row at a time. Hope this will be helpful.
Single RadioButton check at a time with row selection
Thanks,
Shinu.
0

Fatima
Top achievements
Rank 1
answered on 13 Feb 2009, 09:46 AM
Hi Shinu!
Thanks a lot for quick response.
This is a relevant solution what I wanted in my project. But this solution is not working when pagination is applied on the grid. It works pefectly on the first page and moving further on other pages it doesnt works fine.. I mean, I can select multiple radio buttons.
One thing I wanted to suggest in this solution is, the way you called rdSelect_CheckedChanged and you select that row, it should be vice-versa too. That means when you select a row in the grid radio button should also get checked at the same time automatically.
Second thing what I needed is: -
I just wanted to know if I can reduce the server call in this situation.
I dont want to everytime hit the server to select a single row like in
Instead of server side, I want to handle this on client side and for that i just added some piece of code on
Thanks a lot for quick response.
This is a relevant solution what I wanted in my project. But this solution is not working when pagination is applied on the grid. It works pefectly on the first page and moving further on other pages it doesnt works fine.. I mean, I can select multiple radio buttons.
One thing I wanted to suggest in this solution is, the way you called rdSelect_CheckedChanged and you select that row, it should be vice-versa too. That means when you select a row in the grid radio button should also get checked at the same time automatically.
Second thing what I needed is: -
I just wanted to know if I can reduce the server call in this situation.
I dont want to everytime hit the server to select a single row like in
protected void rdSelect_CheckedChanged(object sender, EventArgs e) | |
{ | |
//Select the row whose RadioButton is selected | |
((sender as RadioButton).Parent.Parent as GridItem).Selected = (sender as RadioButton).Checked; | |
} |
Instead of server side, I want to handle this on client side and for that i just added some piece of code on
SelectMeOnly function on client side.
To do that I added one more parameter while calling this function as
public void setGrdRadioButtonOnClick() | |
{ | |
//Create a Radio Button object | |
RadioButton radioButton; | |
for (int i = 0; i < grdSurvey.Items.Count; i++) | |
{ | |
//Find the Radio Button which was selected by the User | |
radioButton = (RadioButton)grdSurvey.Items[i].FindControl("rdSelect"); | |
//Call the javascript function SelectMeOnly in the OnClick event | |
radioButton.Attributes.Add("OnClick", "SelectMeOnly(" + i + "," + radioButton.ClientID + ", " + "'grdSurvey'" + ")"); | |
} | |
} | |
I am sending the data item (see line number 10 above) count of grid item and handling this in the client function below:
function SelectMeOnly(itemNum, objRadioButton, grdName) | |
{ | |
var i, obj, pageElements; | |
if(navigator.userAgent.indexOf("MSIE")!= -1) | |
{ | |
//IE browser | |
pageElements = document.all; | |
} | |
else if(navigator.userAgent.indexOf("Mozilla") != -1 || navigator.userAgent.indexOf("Opera")!= -1) | |
{ | |
//FireFox/Opera browser | |
pageElements = document.documentElement.getElementsByTagName("input"); | |
} | |
for (i=0; i < pageElements.length; i++) | |
{ | |
obj = pageElements[i]; | |
if (obj.type == "radio") | |
{ | |
if (objRadioButton.id.substr(0, grdName.length) == grdName) | |
{ | |
if (objRadioButton.id == obj.id) | |
{ | |
obj.checked = true; | |
} | |
else | |
{ | |
obj.checked = false; | |
} | |
} | |
} | |
} | |
var masterTable = $find("<%=grdSurvey.ClientID%>").get_masterTableView(); | |
for (i=0; i < masterTable.get_dataItems().length; i++) | |
{ | |
var dataItem = masterTable.get_dataItems()[i]; | |
if (i == itemNum ) | |
{ | |
dataItem.set_selected(true); | |
} | |
else if (i != itemNum && dataItem.get_selected() == true) | |
{ | |
dataItem.set_selected(false); | |
} | |
} | |
} |
I added the code (line 35 to line 48) to select the data item in grid. But this is only working on the first page of grid whereas when we move on next page it is not working at all.. rather it started selected mulitple rows itself.
Please suggest if I am going wrong.. I am very new to this .. so must be committing big blows.
Thanks!
With Regards,
Fatima Khan