Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have created gridview with radiobutton in item template field.

i have bind id to radiobutton in gridview.
But i dont want to display it because it is primary key and user need not to see that

HOw to hide that and capture selected radiobutton value on Submit button.
Posted
Updated 8-Jul-14 23:14pm
v2
Comments
Raje_ 9-Jul-14 5:21am    
If you don't show the radio button, how will you select the row? Is it by clicking on row, In this case there is no need to take radio button.
[no name] 9-Jul-14 5:50am    
no i want to display radio button to select row. If i wont hide then how to capture selected radiobutton value
Raje_ 9-Jul-14 6:01am    
So you want to display radio button and you want to hide id column so that user can see only radio button. Am i right?
[no name] 9-Jul-14 6:02am    
right
Raje_ 9-Jul-14 6:09am    
One more question why are you using radio button instead of it you can use Check box so that user can select multiple row at same time.

1 solution

It is always good to take Checkbox to select the row from gridview. So that user can select multiple row same time.
here i have made a simple demo.
Your Gridview :
ASP.NET
<asp:gridview id="gridview" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
          <columns>
              <asp:templatefield headertext="Select">
                  <HeaderTemplate>
                      <span title="Select">Select</span>
                      <asp:checkbox id="chkAddAllProd" onclick="checkUncheckAll(this)" tooltip="Select All">
                          runat="server" value="1" BorderStyle="None"></asp:checkbox>
                  </HeaderTemplate>
                  <itemtemplate>
                      <asp:checkbox id="chkAddProduct" runat="server" value="<%# Eval("Id")%>" borderstyle="None">
                      </asp:checkbox>
                  </itemtemplate>
              </asp:templatefield>
              <%--Your other template field--%>
          </columns>
      </asp:gridview>

You can also select all the row by selecting the header checkbox :
here is the jquery code :
JavaScript
function checkUncheckAll(chk) {
    $('#<%=gridview.ClientID %>').find("input:checkbox").each(function () {
        if (this != chk) {
            this.checked = chk.checked;
        }
    });
}


Hope it will help you.

Good luck.
 
Share this answer
 
Comments
[no name] 9-Jul-14 6:22am    
Thanks for example. User can select only one row so i am using radiobutton.
I got solution.
Raje_ 9-Jul-14 6:25am    
You should have told it in your question :( Any ways good to hear that you got solution. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900