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

Grid CommandItemTemplate

2 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bhavesh
Top achievements
Rank 1
Bhavesh asked on 09 Dec 2009, 08:27 AM
Hello,
         I used CommandItemtemplate for edit, insert, update and delete opration. In command item put icons for this operation and used EditForms (FormTemplate) for insert and update operation. User can select row any row from gridview list and perform operation what he/she wants.

My question is i want to find any control from FormTemplate when user click on update icon from commandtemplate. How to find control from selected row formtemplate using CommandItemTemplate.

Reply me soon

Regards,
Bhavesh Rana

2 Answers, 1 is accepted

Sort by
0
Accepted
Hus Damen
Top achievements
Rank 1
answered on 11 Dec 2009, 12:00 PM
Hi Bhavesh,

Let's say you have this template:

<telerik:RadGrid ID="RadGrid1" runat="server" ... > 
        <MasterTableView CommandItemDisplay="Top" EditMode="EditForms"
            <CommandItemTemplate> 
                ... 
            </CommandItemTemplate> 
            <EditFormSettings EditFormType="Template"
                <FormTemplate> 
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind( "MyColumn1" ) %>'
                    </asp:TextBox><br /> 
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind( "MyColumn2" ) %>'
                    </asp:TextBox> 
                </FormTemplate> 
            </EditFormSettings> 
        </MasterTableView> 
</telerik:RadGrid> 

Then you can try the following itemCommand event handler:

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        ... 
        if (e.CommandName == RadGrid.UpdateEditedCommandName) 
        { 
            GridItem[] editFormItems = RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem); 
            foreach (GridItem item in editFormItems) 
            { 
                GridEditFormItem editedItem = item as GridEditFormItem; 
                { 
                    if (editedItem.IsInEditMode) 
                    { 
                        Response.Write("TextBox1.Text: " + (editedItem.FindControl("TextBox1"as TextBox).Text + "<br/>"); 
                        Response.Write("TextBox2.Text: " + (editedItem.FindControl("TextBox2"as TextBox).Text + "<br/>"); 
                    } 
                } 
            } 
        } 
    } 


I hope this helps.
Hus


0
Bhavesh
Top achievements
Rank 1
answered on 12 Dec 2009, 06:17 AM
Hello Hus,
                  Thanks for this solution it works successful.


Thanks & Regards,
Bhavesh Rana
Tags
Grid
Asked by
Bhavesh
Top achievements
Rank 1
Answers by
Hus Damen
Top achievements
Rank 1
Bhavesh
Top achievements
Rank 1
Share this question
or