Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a location datalist with check box. I can refer the location name in text field and bind id through its value field...I need to get a selected text and its id...already am get value through its value field..how to get that location names with comma seperator and stored into hiddenfield2?

Javascript :

JavaScript
   $("[id$='SubmitBtn']").click(function () {
    var ISBN = [];
  
    $("[id$='LocationDataList'] input[type=checkbox]:checked").each(function () {
        ISBN.push($(this).val());
        
    }); 
    $("[id$='HiddenField1']").val(ISBN);         

});


Aspx code:
ASP.NET
<pre lang="HTML">
<asp:DataList ID="LocationDataList" runat="server" 
      RepeatDirection="Vertical" Width="100%">
      <itemtemplate>
 <table>
     <tr>
<td>
    <input id="Checkbox1" name="LocatIDChkBox"  runat="server" type="checkbox" value='<%#Eval("LocationID") %>' />
    <asp:Label ID="LocatNamelbl" CssClass="normaltext"  runat="server" Text='<%# Eval("LocationName") %>'/>
</td>
     
     </tr>
 </table>
      </itemtemplate>
      <FooterTemplate>
      <tr><td align="center">
 <asp:ImageButton ID="SubmitBtn" ImageUrl="~/images/more.png" OnClick="SubmitBtn_Click" runat="server" Height="25px" Width="50px" /></td></tr>
      </FooterTemplate>
  </asp:DataList>
Posted
Updated 3-Dec-13 21:52pm
v2

1 solution

Hi
User Array Join method to perform comma separated string

C#
<script type="text/javascript">

        $(function () {

            $("[id$='SubmitBtn']").click(function () {

                alert('testing');
                var ISBN = [];

                $("input:checkbox:checked", '#LocationDataList').each(function () {

                    var location = $('span', $(this).parent()).text();
                    ISBN.push(location);
                });
                alert(ISBN.join(','));
                $("[id$='HiddenField1']").val(ISBN.join(','));
                // alert(ISBN);


                return false; ;
            });



        });
    </script>
 
Share this answer
 
v2
Comments
SnvMohan 4-Dec-13 4:35am    
i need to take a selected location name displayed on check box...i am already get a value ..
Karthik_Mahalingam 4-Dec-13 4:42am    
Display text u need or the Client ID of the check box ???
SnvMohan 4-Dec-13 4:36am    
in ISBN variable i have a selected a location id's...I need to get selected location name and stored into another variable
Karthik_Mahalingam 4-Dec-13 4:43am    
I have made like this in data source.


DataTable dt = new DataTable();
dt.Columns.Add("LocationID", typeof(string));
dt.Columns.Add("LocationName", typeof(string));
dt.Rows.Add("aaa", "apple");
dt.Rows.Add("bbb", "bat");
dt.Rows.Add("ccc", "cat");
LocationDataList.DataSource = dt;
LocationDataList.DataBind();
Karthik_Mahalingam 4-Dec-13 4:44am    
ok fine i got your problem..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900