Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use radio buttons and the 'Template' column feature of a GridView. The GridView markup would look like this:</p> <pre><code> &lt;asp:GridView ID="gvTest" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvTest_RowDataBound"&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="Column 1"&gt; &lt;ItemTemplate&gt; &lt;asp:RadioButton ID="rbSelect1" runat="server" Text="" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Column 2"&gt; &lt;ItemTemplate&gt; &lt;asp:RadioButton ID="rbSelect2" runat="server" Text="" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>The trick then would be to correctly set the 'GroupName' property of each radio button so that each row of the resulting grid is treated as a single radio button group by the browser. That's where the 'OnRowDataBound' handler specified on the grid comes into play. The definition of the 'gvTest_RowDataBound' handler method could be something like:</p> <pre><code>protected void gvTest_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { RadioButton rb1 = (RadioButton)e.Row.FindControl("rbSelect1"); RadioButton rb2 = (RadioButton)e.Row.FindControl("rbSelect2"); rb1.GroupName = rb2.GroupName = string.Format("Select_{0}", e.Row.RowIndex); } } </code></pre> <p>By appending the row index to the group name to both of the radio buttons in each row you're going to ensure that the browser will treat them as a group and only allow the selection of one value per row. The result would look something like this:</p> <p><a href="http://i46.tinypic.com/2yoe3c3.png" rel="nofollow noreferrer">GridView screenshot http://i46.tinypic.com/2yoe3c3.png</a></p>
 

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