This is a migrated thread and some comments may be shown as answers.

find control in ItemEditing

5 Answers 156 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Mohamad Javad
Top achievements
Rank 1
Iron
Mohamad Javad asked on 09 Nov 2014, 05:07 AM
hi
which find control for example, button, in RadListView1_ItemEditing

i try below code,but give error.



  protected void RadListView1_ItemEditing(object sender, RadListViewCommandEventArgs e)
    {
RadListViewEditableItem editedItem = (RadListViewEditableItem)e.ListViewItem;

 RadTextBox txtSubject =(RadTextBox)editedItem.FindControl("txtSubject");

txtSubject .Text="hi";

}
please help me.
thanks

5 Answers, 1 is accepted

Sort by
0
Mohamad Javad
Top achievements
Rank 1
Iron
answered on 09 Nov 2014, 08:39 AM
no any one, to help me?
0
Mohamad Javad
Top achievements
Rank 1
Iron
answered on 11 Nov 2014, 07:38 AM
please Help!!!!!!!
0
Eyup
Telerik team
answered on 13 Nov 2014, 12:47 AM
Hi Mohamad,

Please try executing this logic on ItemDataBound event handler:
http://www.telerik.com/help/aspnet-ajax/listview-accessing-controls.html

You can also check the approach demonstrated in the following live sample for extracting the values to be updated:
http://demos.telerik.com/aspnet-ajax/listview/examples/dataediting/manualediting/defaultcs.aspx

Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mohamad Javad
Top achievements
Rank 1
Iron
answered on 13 Nov 2014, 10:34 AM
hi

my normal view form have textbox with text(for example text box have this text > "Nice") ,  when i press the edit button, I have need, to add some text( for example add > "Re: ") to texbox.
also need add  row number ,add to the textbox .
in otherwise the texbox befor edite="nice"
and after press edit="Re: nice"+ row number


when i set value to propertice in RadListView1_PreRender or RadListView1_ItemCreated , give error

for example when i set :
   protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)
    {
    if (e.Item is RadListViewEditableItem && e.Item.IsInEditMode)
        {
         
            RadEditor txtEditor = e.Item.FindControl("txtEditor") as RadEditor;

           txtEditor.Content += "Re: " + txtEditor.Content ;

        }
}


or
 protected void RadListView1_PreRender(object sender, EventArgs e)
    {

        RadEditor txtEditor = RadListView1.FindControl("txtEditor") as RadEditor;

        txtEditor.Content += "Re: " + txtEditor.Content;
}

give Error.

please Help Me




0
Konstantin Dikov
Telerik team
answered on 18 Nov 2014, 07:36 AM
Hello Mohamad,

In order to find controls within an item you must use the RadListViewDataItem object or the RadListViewEditableItem for the edit mode. You also need to handle the OnItemDataBound event, where the controls will be bound to a data and will hold the values that you need.

For your convenience, following is a simple example demonstrating how to accomplish the result you need:
<telerik:RadListView runat="server" ID="RadListView1" OnNeedDataSource="RadListView1_NeedDataSource"
    OnItemDataBound="RadListView1_ItemDataBound">
    <ItemTemplate>
        <asp:Label runat="server" ID="Label1" Text='<%# Eval("SomeField") %>'></asp:Label>
        <telerik:RadButton runat="server" ID="RadButton1" CommandName="Edit" Text="Edit"></telerik:RadButton>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadTextBox runat="server" ID="RadTextBox1" Text='<%# Eval("SomeField") %>'></telerik:RadTextBox>
    </EditItemTemplate>
</telerik:RadListView>

And the code-behind:
protected void RadListView1_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("SomeField", typeof(string));
    for (int i = 0; i < 1; i++)
    {
        table.Rows.Add(i, "Nice");
    }
 
    (sender as RadListView).DataSource = table;
}
 
protected void RadListView1_ItemDataBound(object sender, RadListViewItemEventArgs e)
{
    if (e.Item is RadListViewEditableItem)
    {
        RadListViewEditableItem editItem = e.Item as RadListViewEditableItem;
        RadTextBox textBox = editItem.FindControl("RadTextBox1") as RadTextBox;
        textBox.Text = "Re: " + textBox.Text;
    }
}


Best Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ListView
Asked by
Mohamad Javad
Top achievements
Rank 1
Iron
Answers by
Mohamad Javad
Top achievements
Rank 1
Iron
Eyup
Telerik team
Konstantin Dikov
Telerik team
Share this question
or