Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to split a string in a datatable and add into new rows using Linq C#?
    primarykey
    data
    text
    <p>I am new to linq. I am using linq to get vlaues from datalist control and creating a datatable with that values. The datatable contains three columns. In that, sometimes the 'Answer' column is having a data which is comma separated. <img src="https://i.stack.imgur.com/cOPi3.png" alt="You can see the image of datatable with comma separated column"></p> <pre><code> DataTable SaveAnswer = clsSource.SetData(); var df = from DataListItem dli in PollDataList.Items let z = ((HiddenField)dli.FindControl("IDReqHiddenField")) let y = ((RadioButtonList)dli.FindControl("rdblstPollOptions")) let v = ((CheckBoxList)dli.FindControl("CheckBoxListMultiplePollOptions")) select new { PollId=z.Value, Answered1 = y.SelectedValue, Answered2=v.Items.Cast&lt;ListItem&gt;().Where(r=&gt;r.Selected) }; var result = from p in df select SavePollAnswer.LoadDataRow( new object[] { p.PollId,p.Answered1+string.Join( ", ", p.Answered2 ),"" }, false); SavePollAnswer = result.CopyToDataTable(); </code></pre> <p>And here is my design</p> <pre><code>&lt;asp:DataList ID="PollDataList" runat="server" CssClass="poll-preview"&gt; &lt;ItemTemplate&gt; &lt;asp:HiddenField ID="PollIDReqHiddenField" Value='&lt;%# Eval("PollID") %&gt;' runat="server" Visible="false" /&gt; &lt;asp:Label ID="lblReqQuestionNumber" runat="server" Text='&lt;%# Eval("NoofPollQuestion") %&gt;' Font-Bold="true"&gt;&lt;/asp:Label&gt;&lt;br /&gt; &lt;asp:Label ID="lblRequiredPollQusetion" runat="server" Text='&lt;%# Eval("PollQuestions") %&gt;' Font-Bold="false"&gt;&lt;/asp:Label&gt; &lt;asp:Label ID="lblReqNotification" runat="server" ForeColor="Red" CssClass='&lt;%# Eval("PollReq") %&gt;' Text="*" Font-Bold="true"&gt;&lt;/asp:Label&gt; &lt;asp:RadioButtonList ID="rdblstPollOptions" DataSource='&lt;%# Eval("PollOptionsReq") %&gt;' runat="server"&gt;&lt;/asp:RadioButtonList&gt; &lt;asp:CheckBoxList ID="CheckBoxListMultiplePollOptions" DataSource='&lt;%# Eval("PollOptionsMul") %&gt;' runat="server" RepeatDirection="Vertical" RepeatColumns="1"&gt;&lt;/asp:CheckBoxList&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; </code></pre> <p>But we want the datatable output like this <img src="https://i.stack.imgur.com/SLVF3.png" alt="Expected Output"></p> <p>Thanks in advance!</p>
    singulars
    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