check only one checkbox in gridview

i have list of items which have checkboxes in front,
so i try to only allow only one checkbox can be checked in the gridview.
<asp:GridView ID="gvLS" runat="server" 
        AutoGenerateColumns="False" AllowPaging="True" CssClass="datatable"
                    CellPadding="5" BorderWidth="1px" BorderColor="#6E6E6E" 
                 Font-Names="Arial" Font-Size="Small" 
                PageSize="5" GridLines="None" AlternatingRowStyle-BackColor="#efefef" 
            Width="300px" 
                 HeaderStyle-HorizontalAlign="Left" 
            AllowSorting="True"   >
                    <HeaderStyle BackColor="#BDBDBD" />
                    <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:CheckBox id="cbCheckLevel" runat="server" />
                            <asp:Label ID="lblIDField" Visible="false" Text='<%# Eval("id") %>' runat="server" />
                    
                         </ItemTemplate>
                    </asp:TemplateField>

                    <asp:BoundField HeaderText="Level Code" DataField="code" 
                            SortExpression="code" HeaderStyle-ForeColor="Black"
                            HeaderStyle-CssClass="first" ItemStyle-CssClass="first" ReadOnly="True"  
                            HeaderStyle-HorizontalAlign="Left"  ItemStyle-HorizontalAlign="Left">
<HeaderStyle CssClass="first" ForeColor="Black"></HeaderStyle>

<ItemStyle CssClass="first"></ItemStyle>
                        </asp:BoundField>
                        
                            <asp:BoundField HeaderText="Level Name" DataField="name" 
                            SortExpression="name" HeaderStyle-ForeColor="Black"
                            HeaderStyle-CssClass="first" ItemStyle-CssClass="first" ReadOnly="True"  
                            HeaderStyle-HorizontalAlign="Left"  ItemStyle-HorizontalAlign="Left">
<HeaderStyle CssClass="first" ForeColor="Black"></HeaderStyle>

<ItemStyle CssClass="first"></ItemStyle>
                        </asp:BoundField>
                       
                     
                    </Columns>
        
                         </asp:GridView>

Open in new window

LVL 1
doramail05Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sarika30Commented:
try using radio buttons in the same group.
0
doramail05Author Commented:
found article on repeater,

http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c12371/

changed to gridview
aspx
----

<asp:TemplateField>
                        <ItemTemplate>
                            <asp:RadioButton ID="rdoSelected" GroupName="gn01" runat="server" />
                            <asp:Label ID="lblLIDField" Visible="false" Text='<%# Eval("id") %>' runat="server" />
                    
                         </ItemTemplate>
                    </asp:TemplateField>
codebehind
----------

protected void gvLS_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            RadioButton rdo = (RadioButton)e.Row.FindControl("rdoSelected");
            string script =
               "SetUniqueRadioButton('gvLevel.*gn01',this)";
            rdo.Attributes.Add("onclick", script);
        }
    }

javascript
----------
<script type="text/javascript">
function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sarika30Commented:
It is using radio buttons only...thts what i suggested :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.