开发者

Reading textareas in datalist within itemcommand

开发者 https://www.devze.com 2023-03-20 21:24 出处:网络
I have a DataList and inside of each item there is an ImageButton that needs to save the contents of an associated textarea.I normally would pass parameters using the CommandArgument tag, but the text

I have a DataList and inside of each item there is an ImageButton that needs to save the contents of an associated textarea. I normally would pass parameters using the CommandArgument tag, but the text inside the description is very long and I do not want to write it out into the commandargument for all the items being displayed. Instead, how can I find the ID of the associated textarea so I can save the text the user changes/enters?

I tried passing 'this' into the commandargument but I do not think it is working as it just passes the object for the button and not the whole item.

I realize this seems like a basic question but I've searched for over an hour. Your help 开发者_如何学编程is very appreciated.

<asp:ImageButton ID="saveDesc" runat="server" AlternateText="Save Image Description" BorderStyle="None" ImageUrl="..\..\images\save.png" CommandArgument='this' CommandName="SaveDescription"  />
<asp:TextBox ID="description" runat="server" Text='<%#Eval("description")%>' style="font-weight:bold; width:100%" TextMode="MultiLine" Height="50px"/>

There are actually multiple DataLists inside of multiple Accordion views, but I'm not sure if this is relevant to the answer.

Thanks


You can do like...

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
 if (e.CommandName == "SaveDescription")
    {
    DataListItem item = ((DataListItem)((ImageButton)e.CommandSource).NamingContainer);
    TextBox description = (TextBox)item.FindControl("description");
    description.Text // return your text 
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消