Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code>&lt;%@ Page Language="C#" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;script runat="server"&gt; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { System.Collections.Generic.List&lt;int&gt; Values = new System.Collections.Generic.List&lt;int&gt; { 1, 2, 3, 4, 5, 6, 7 }; grdTest.DataSource = Values; grdTest.DataBind(); } } protected void btnSubmit_Click(object sender, EventArgs e) { HtmlInputCheckBox chkTest = null; string SelectedValues = ""; foreach (GridViewRow row in grdTest.Rows) { chkTest = (HtmlInputCheckBox) row.FindControl("chkTest"); if (chkTest != null &amp;&amp; chkTest.Checked) { SelectedValues += (SelectedValues == "" ? chkTest.Value : ", " + chkTest.Value); } } litValues.Text = SelectedValues; } &lt;/script&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:GridView ID="grdTest" runat="server"&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;input id="chkTest" type="checkbox" name="chkTest" runat="server" value="&lt;%# (int)Container.DataItem %&gt;" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Text="Submit" /&gt; &lt;br /&gt; &lt;asp:Literal ID="litValues" runat="server"&gt;&lt;/asp:Literal&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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