DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2004

    DataGrid with Checkedbox/Radio button

    As far as I know, We can added some controls like radio buttons, checked box into DataGrid's Templete Column. But I think it can decrease the performance of Datagrid...
    Suppose : Many records are displayed in that grid. Radio buttons are added into the datagrid.. If the user change one radio button to another, it will take long time...
    OR.. Checked Boxes are added into the grid and then, the user select all checked boxes by checking "Check All" Checkbox at the top of grid.. It will take very long time if many records are displayed in that grid...

    My Problem is I need to use the checked boxes/option boxes in my grid.. But loading time is too much..
    So, How should I do?

    Any suggestions would be appreciated.
    Thanks in advance.
    Best Regards,
    Michael Sync

    The more you share,The more you get

  2. #2
    Join Date
    Feb 2007
    Your problem in loading time because ASP.net triggers "evey" event of any server side control by reloaing the page while posting some data back to it, which definitely reduce performance.

    So I suggest you to choose javascript for this in collaboration with ASP .net, infact ASP .net translates most of its commands into javascript.

    To have radio buttons to select each row inside the datagrid follow the following easy steps:

    .ASPX File:

    In aspx page add the following javascript function

    <script language=javascript>
    function SelectMeOnly(objRadioButton, grdName) { var i, obj;
    //example of radio button id inside the grid (grdAddress): grdAddress__ctl2_radioSelect
    for (i=0; i<document.all.length; i++) {
    obj = document.all(i);
    if (obj.type == "radio") {
    if (objRadioButton.id.substr(0, grdName.length) == grdName)
    if (objRadioButton.id == obj.id)
    obj.checked = true;
    obj.checked = false;

    Your Radio Button ASP .net Control inside the data grid would look like this:

    <asp:RadioButton ID="radioSelect" GroupName='<%#DataBinder.Eval(Container.DataItem,"RecID")%>' Runat=server ></asp:RadioButton>

    Here I used GroupName property to just Identify the row no in Database, where datagrid is bound to any datasource in page load event. RecID in this case is the Primary Key in the table holding unique RecID for each row in the table. You can replace this with your table's field name, or remove it at all if you donot want to record the row number for each radio button. You can also use the Text property to set text for the radio button.

    Thats all concerned in aspx page.

    .CS File

    Here Make the following function and call it in Page Load event, this function would set the OnClick event of each RadioButton inside the data grid, let say your data grid name is "grdDataGrid":

    public void SetGrdRadiosOnClick()
    int i;
    RadioButton B;

    for (i = 0; i<grdDataGrid.Items.Count; i++)
    B = (RadioButton) grdDataGrid.Items[i].FindControl("radioSelect");
    B.Attributes.Add("OnClick", "SelectMeOnly(" + B.ClientID + ", "+ "'grdDataGrid'" + ")");

    You got it, Thats all it need to have radio button functionality to select rows in Datagrid and in fastest way.

    Final thing, if you want to get which radio is selected and at which row, i.e. which row in database the selected radio button represents then you cn use the following function, let say you have a button name "btnSelect". (Remember we set the Unique Row ID of database in GroupName property of each radio button):
    GridName is "grdDataGrid"
    RadioButton inside the grid was "radioSelect" which is repeated for each row

    public void btnSelect_Click(object sender, System.EventArgs e)
    RadioButton B;
    int i, RecID=0;
    for (i = 0; i<grdDataGrid.Items.Count; i++)
    B = (RadioButton) grdDataGrid.Items[i].FindControl("radioSelect");
    if (B.Checked)
    RecID = int.Parse(B.GroupName);

    Response.Redirect("./ProcessRecord.aspx?RecID=" + RecID);

Similar Threads

  1. radio button inside datagrid
    By Balaji N.S in forum .NET
    Replies: 3
    Last Post: 02-17-2007, 02:36 PM
  2. button listener not working
    By DrunkinP in forum Java
    Replies: 0
    Last Post: 03-31-2005, 09:36 AM
  3. Populating a 'button' column in DataGrid
    By moben in forum VB Classic
    Replies: 6
    Last Post: 01-16-2002, 03:05 AM
  4. Search Button for datagrid
    By Wayne in forum VB Classic
    Replies: 1
    Last Post: 03-09-2001, 09:52 AM
  5. Need help on Datagrid, datacombo and command button.
    By Wendy Lee in forum VB Classic
    Replies: 1
    Last Post: 03-01-2001, 09:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.