Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello frens, i have this small problem in asp.net

i have a code like this...

XML
<asp:DataList ID="DataList1" runat="server" >


          <ItemTemplate>
              <asp:Label ID="Label2" runat="server" Text='<%#Eval("status") %>'></asp:Label>
              <br />    <hr />

              <asp:DataList ID="DataList2" runat="server" DataSource='<%#getCommentsByStatID(Eval("statid").ToString()) %>'>
                  <ItemTemplate>
                      <asp:Label ID="Label1" runat="server" Text='<%#Eval("comment") %>'></asp:Label>
                  </ItemTemplate>
              </asp:DataList>

              <asp:TextBox ID="txtcomment" runat="server" Text='<%# Container.DataItem %>' ></asp:TextBox>
              <asp:Button ID="btncomment" runat="server" Text="Post" PostBackUrl='<%# "~/Default2.aspx?statusid="+Eval("statid")%>' />

          </ItemTemplate>

          <SeparatorTemplate><hr /></SeparatorTemplate>


      </asp:DataList>



when the button btncomment is clicked, i need to get the text of txtcomment saved in the database by knowing the status id.. i can get the status id from the query string but i cannot get the text of txtcomment ..

please help with some suitable codes or links .........

with thanks
Posted

1 solution

Add ItemCommand Event on your datalist as given below.

ASP.NET
<asp:datalist id="DataList1" runat="server" onitemcommand="DataList1_ItemCommand" xmlns:asp="#unknown">
            <itemtemplate>
                <asp:textbox id="txtcomment" runat="server" text=""></asp:textbox>
            </itemtemplate>
</asp:datalist>


Then on item command event, you can get text of your textbox easily.

C#
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        TextBox txtComments = (TextBox)e.Item.FindControl("txtcomment");

        string Comments = txtComments.Text; // here you can get text from your textbox

    }

}



Accept Solution if it helps you.
 
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