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

How retreive GridColumn values on UserControl in Edit mode

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
alsi
Top achievements
Rank 1
alsi asked on 01 Aug 2008, 07:05 AM
Dear All!

I am quite newbie and don't know how to retreive the values on a custom UserControl in Edit mode. I have the following grid structure:

....
<MasterTableView ShowFooter="false" DataKeyNames="ID" GridLines="None" CommandItemDisplay="Top">
                        <Columns>
                            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
                            <telerik:GridTemplateColumn AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:LinkButton runat="server" ID="btnDelete" Text="Delete" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn UniqueName="ID" DataField="ID"  DataType="System.Int32" Visible="false" />
                            <telerik:GridBoundColumn DataField="AnswerTypeLabel" UniqueName="AnswerTypeLabel"
                                HeaderText="Answer Type" DataType="System.String" />
                            <telerik:GridBoundColumn DataField="AnswerMeasureLabel" UniqueName="AnswerMeasureLabel"
                                HeaderText="Measure Type" DataType="System.String" />
                              </Columns>
                        <EditFormSettings UserControlName="CustomEditControl.ascx" EditFormType="WebUserControl">
                            <EditColumn UniqueName="EditCommandColumn1">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
....

And I want to access to the edited GridBound and GridTemplate columns values on the Code Behind file of the UserControl file (CustomEditControl.ascx)

I am sure it's possible but don't know how.

thanks,
G.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Aug 2008, 09:08 AM
Hi,

To access the UserControlForm and thereby get access to the Controls in the form you can try out the following code.
ascx:
<asp:TextBox ID="TextBox1" Text='<%#DataBinder.Eval(Container,"DataItem.FirstName") %>' runat="server"

aspx:
 <EditFormSettings EditFormType="WebUserControl" UserControlName="WebUserControl.ascx"
        <EditColumn UniqueName="EditCommandColumn1"></EditColumn> 
      </EditFormSettings>  


cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditFormItem editItem = (GridEditFormItem)e.Item; 
            UserControl userControl = (UserControl)editItem.FindControl(GridEditFormItem.EditFormUserControlID); 
            TextBox txtbx = (TextBox)userControl.FindControl("TextBox1"); 
             
        } 
    } 

To get the edited values, you can try out the following code to get the text of the TextBox as well.
cs:
 protected void Grid1_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
        { 
 
            GridEditFormItem editItem = (GridEditFormItem)e.Item; 
            UserControl userControl = (UserControl)editItem.FindControl(GridEditFormItem.EditFormUserControlID); 
            TextBox txt1 = (TextBox)userControl.FindControl("TextBox1"); 
            string strtxt=txt1.Text; 
        } 
    } 

Thanks
Princy.

Tags
Grid
Asked by
alsi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or