Results 1 to 2 of 2

Thread: Using button code on a datagrid

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Using button code on a datagrid

    I need to put buttons in a datagrid. I know how to do this with the
    <templatecolumn> , but my question is how do I access it in the
    codebehind .vb file, if the number of buttons is variable? I need to put some
    code in the _Click event of each button.

  2. #2
    New Member
    Join Date
    Aug 2004
    Location
    Chennai
    Posts
    7

    Re: Using button code on a datagrid

    Hi,

    Try this code. Here is the code for how to put Radio Button in Datagrid, and how to select the perticular row which is clicked is given..

    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:RadioButton AutoPostBack="True" id="rbSel" OnCheckedChanged="SelectOpt" runat="server"></asp:RadioButton>
    </ItemTemplate>
    </asp:TemplateColumn>

    -------------------------------------------------------------------------

    public void SelectOpt(object sender,EventArgs e)
    {

    System.Web.UI.WebControls.RadioButton rb = new System.Web.UI.WebControls.RadioButton();
    rb = (System.Web.UI.WebControls.RadioButton) sender;
    sRbText = rb.ClientID;

    foreach (DataGridItem i in Dg.Items )
    {
    rb = (System.Web.UI.WebControls.RadioButton) i.FindControl ("rbSel");
    rb.Checked = false;
    if (sRbText==rb.ClientID)
    {
    rb.Checked = true;
    //txtSiraNo.Text = rb.Text.Trim();
    // if you want to get a property of the selected id
    Dg.SelectedIndex =i.ItemIndex;

    }
    }
    }

    Regards,
    Dharmi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width