简体   繁体   中英

Getting DataList selected item in a text box

I have a DataList on my webpage that is populated by ItemTemplate . Each <tr> in ItemTemplate has a LinkButton with CommandName=Select . When the user clicks on the link button, the corresponding text should appear in the TextBox below.

Inside the ItemTemplate, each row also has a label control which I have put up to be able to be able to find the control and typecast.

Inside the properties window, I am not able to locate the AutoPostBack property.
What event has to be used in this case? Would the SelectedIndexChanged serve the purpose?

How do I find the corresponding data from this row and assign it to my textbox?

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                ((TextBox)e.Item.FindControl("Textboxname")).Text = ((Label)e.Item.FindControl("LabelName")).Text;
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM