Click here to Skip to main content
15,903,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a datalist which contains textbox and lables, i want to retrieve the data from datalist which is entered in the textbox on a button click.. please help me how to retrieve data from textbox in datalist ..

Here is my code..

XML
<asp:DataList ID="dlqty" Width="100%" runat="server" RepeatColumns="1"
                RepeatDirection="Vertical">
                    <ItemTemplate>
            <tr>
            <td style="padding-left:5px;padding-right:5px;">
            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bdr">
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="40" class="abtext" style="border-bottom:#dddddd solid 1px; padding-left:10px">
                    <asp:Label ID="lblproduct" runat="server" CssClass="abtext"><%#Eval("Product") %></asp:Label>
                    </td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td style="padding-top:1px;"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabo">
                  <tr>
                    <td width="22%" height="30" align="center" valign="top" style="padding-top:5px;"><img src="images/noimage.png" width="105" height="105" /></td>
                    <td width="28%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td height="20" class="gntext2">Description</td>
                      </tr>
                      <tr>
                        <td height="77"><asp:Label ID="lbldescription" runat="server" CssClass="smtext"><%#Eval("description") %></asp:Label></td>
                      </tr>

                    </table></td>
                    <td width="1%" align="center"><img src="images/dev1.png" width="1" height="92" /></td>
                    <td width="25%" style="padding-left:5px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td height="20">&nbsp;</td>
                      </tr>
                      <tr>
                        <td height="20" class="smtext2" style="padding-left:10px;">MRP: $ </td>
                      </tr>
                      <tr>
                        <td height="20" class="gntext2" style="padding-left:10px;">Qnty: <asp:Label ID="lblqty" runat="server"><%#Eval("quantity") %></asp:Label> </td>
                      </tr>
                      <tr>
                        <td height="20" class="btext" style="padding-left:10px;">&nbsp;</td>
                      </tr>
                    </table></td>
                    <td width="8%">&nbsp;</td>
                    <td width="16%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td height="35" align="center"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','images/buy_ro.png',1)">
                          <asp:TextBox runat="server" ID="txtno" CssClass="txtbox"></asp:TextBox>


                        </a></td>
                      </tr>
                      <tr>
                        <td height="20" align="center" class="bnutext">Qnty Required </td>
                      </tr>
                    </table></td>
                  </tr>
                </table></td>
              </tr>
            </table>
             </td>
          </tr>
                  <tr>
          <td height="30px">
          </td>
            </ItemTemplate>
            <FooterTemplate>

     <asp:ImageButton ID="btnreg"  runat="server" ImageUrl="~/images/sub.PNG" CommandName="rsm"/>

            </FooterTemplate>
            </asp:DataList>
Posted

1 solution

You need to use FindControl method.

Try something like:
C#
foreach (DataListItem item in myDataList.Items)
{
    TextBox myTextBox = (TextBox)item.FindControl("myTextBox");
    string text = myTextBox.text;
    // Do what you need to with this string value now
}
 
Share this answer
 

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