Note that there are some explanatory texts on larger screens.

plurals
  1. PORadioButton Selection in GridView
    primarykey
    data
    text
    <p>Here is my requirement.</p> <p>I had 3 groups and having set of emplyees under each group. </p> <p>So, I had placed 3 labels(To display groupname) 3 gridviews(to dispalay set of employees from each group) in a DataList. all the rows in 3 GridViews having RadioButtons.</p> <p>Now problem is RadioButton is behaving like a checkbox, it is allowing multiple selections.</p> <p>But, I need to select Only one RADIOBUTTON among all 3 Gridviews. How this can be acheived. Can Someone here help me?</p> <pre><code>/********* Displaying Group Name and Its set of employes **********/ </code></pre> <p>/<strong><em>*</em>**</strong> This loop will execute 3 times as I had 3 groups. <strong><em>*</em>***</strong>/</p> <pre><code>protected void dlGraphItemDataBound(object sender, DataListItemEventArgs e) { MyList dataitem = (MyList)e.Item.DataItem; if (dataitem != null) { Label lbl = (Label)e.Item.FindControl("lblMyLabel"); lbl.Text = dataitem.GroupName; GridView dg = (GridView)e.Item.FindControl("gvList"); if (dg != null) { List&lt; MyList &gt; groupItem = new List&lt; MyList &gt;(); // List of Employees foreach (MyList item in _empList) { if (item.GroupName.Equals(dataitem.GroupName)) groupItem.Add(item); // Grouping all the emps who had same groupname } SetupReportGrid(dg); // Method to add controls to gridview dynamically dg.SetDataSource(groupItem); //Setting datasource for gridview } } } protected void onRadioButtonClicked(object sender, EventArgs e) { foreach (DataListItem dlItem in dlMyDataList.Items) { GridView grid = (GridView) dlItem.FindControl("gvList"); if (grid != null) { RadioButton selectButton = (RadioButton) sender; GridViewRow row = (GridViewRow) selectButton.NamingContainer; int a = row.RowIndex; foreach (GridViewRow gridRow in grid.Rows) { RadioButton rd = gridRow.FindControl("rdoSelect") as RadioButton; if (rd.Checked) { if (gridRow.RowIndex == a) { rd.Checked = true; } else { rd.Checked = false; } } } } } </code></pre> <p>This is how i tried.... when i select first and second radiobutton in 1st gridview and after the event for 2nd radiobutton both 1st and 2nd radiobuttons got unchecked. As the loop executes for all gridviews and last grid having no radiobuttons checked. finally my code results as no radiobuttons checked</p> <p><strong>Grid View Mark up:</strong></p> <pre><code>&lt;asp:DataList ID="dlMyDataList" runat="server" OnItemDataBound="dlGraphItemDataBound"&gt; &lt;ItemTemplate&gt; &lt;table cellspacing="0" width="100%" &gt; &lt;tr&gt; &lt;td nowrap="nowrap" width="100%" align="left" valign="middle"&gt; &lt;asp:Label ID="lblGroupName" runat="server" CssClass="ssrptsublabel" &gt; &lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100%" nowrap="nowrap" align="left" valign="middle"&gt; &lt;asp:Panel id="pnlReport" runat="server" BorderWidth="0" Width="100%" Wrap="False"&gt; &lt;commoncontrols:MyGridView id="gvList" runat="server" autogeneratecolumns="false" EnableViewState="True"&gt; &lt;/commoncontrols:MyGridViewview&gt; &lt;/asp:Panel&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; **// Assigning controls dynamically to grid view // Having Seperate customized class for gridview, based on that we are adding controls // GridViewColumnControl(ControlTypes, Control_ID, CSS Style, 0, databind,"" );** private void SetupGrid(GridView grid) { IList&lt;GridViewColumn&gt; columns = new List&lt;GridViewColumn&gt;(); GridViewColumn gridColumn = new GridViewColumn(ColumnTypes.TemplateColumn, "", 500, HorizontalAlign.Left,null); GridViewColumnControl control = new GridViewColumnControl(ControlTypes.RadioButton, "rdoSelect", "labelstyle", 0, null, ""); control.Visible = false; control.AutoPostBack = true; control.OnChanged += onRadioButtonClicked; gridColumn.AddControl(control); control = new GridViewColumnControl(ControlTypes.DropDown, "", "style", 0, null, ""); control.Visible = false; gridColumn.AddControl(control); grid.SetColumns(columns); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload