Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
hello frens, i have this small problem in asp.net
 
i have a code like this...
 
<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-Jan-13 5:47am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Add ItemCommand Event on your datalist as given below.
 
<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.
 
    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.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid