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

grid UserControl forms - set properties?

5 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
matt
Top achievements
Rank 1
matt asked on 16 Oct 2008, 05:07 PM
hello,

for all of my grids, i use a custom EditForm of type UserControl. this gives me wonderful design flexibility. however, sometimes i need to do special things in the editform UserControl -- for ex, if our user has read-only access, i need to disable some things.

so, programmatically, how can my hosting ASPX page pass in variables (or set properties, or pass in arguments) on the editform UserControl?


thanks!
matt

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Oct 2008, 04:11 AM
Hello Matt,

Check out the following code to access a control in the UserControl EditForm and disable it based on a condition.
cs:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            if ( user condition
            { 
                GridEditFormItem item = e.Item as GridEditFormItem; 
                UserControl user = item.FindControl(GridEditFormItem.EditFormUserControlID) as UserControl; 
                 TextBox txtbx = user.FindControl("TextBox1") as TextBox;                 
                 txtbx.ReadOnly = true;
                //or txtbx.Enable=false
            }             
        }          
    } 

Thanks
Princy.
0
matt
Top achievements
Rank 1
answered on 17 Oct 2008, 03:29 PM
princy,

thanks. that may work.

but is there no way to simply pass an argument into the UserControl, so that i can perfom all sorts of things in the UserControl's code-behind?


thanks,
matt
0
matt
Top achievements
Rank 1
answered on 20 Oct 2008, 04:01 PM
telerik - is there no other way to pass an argument to the EditForm's UserControl? this way i could manage all kinds of private options inside the "fooControl.ascx.cs" class.

thanks,
matt
0
Vladimir
Top achievements
Rank 1
answered on 20 Oct 2008, 06:47 PM
Matt,

The grid will set DataItem property for your user control (if you have such).
You can use also FormTemplate where you can declare your user control and set any desired property.

Vlad
0
matt
Top achievements
Rank 1
answered on 21 Oct 2008, 02:55 PM
vlad,

i dont understand what you mean. as always, complete code samples are the best example. can you explain/show me what you mean?


thanks,
matt
Tags
Grid
Asked by
matt
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
matt
Top achievements
Rank 1
Vladimir
Top achievements
Rank 1
Share this question
or