Wednesday, December 22, 2010

POC : Check a radiobutton just by clicking the Gridview Row


Check a radiobutton just by clicking the Gridview Row


POC :

ASPX Page :

1. <html>

2. <head runat="server">

3. <title>title>

4.

5. <script type="text/javascript">

6. function toggleSelection(targetID) {

7. var radioButton = document.getElementById(targetID);

8. radioButton.checked = !radioButton.checked;

9. }

10. script>

11.

12. head>

13. <body>

14. <form id="form1" runat="server">

15. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"

16. OnRowDataBound="GridView1_RowDataBound">

17. <Columns>

18. <asp:TemplateField>

19. <ItemTemplate>

20. <input id="rdMoveType" type="radio" runat="server" name="rdMoveType" value="Something" />

21. ItemTemplate>

22. asp:TemplateField>

23. Columns>

24. asp:GridView>

25. form>

26. body>

27. html>



Code Behind :

  1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  2. {
  3. if (e.Row.RowType == DataControlRowType.DataRow)
  4. e.Row.Attributes.Add("onclick", "toggleSelection('" + ((HtmlInputControl)e.Row.FindControl("rdMoveType")).ClientID + "');");
  5. }

Script Language :

You can write code to loop through Gridview rows and uncheck radiobuttons other than selected one


No comments:

Post a Comment