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.
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