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

Switching User Controls inside a RadGrid

1 Answer 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 12 Feb 2009, 02:30 PM
We've got a table of (physical) components and we're displaying some of their data in a RadGrid.  When a user wants to edit a row, we want to display a user control particular to the type of component on that row.  Can the UserControl property be changed at runtime?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Feb 2009, 04:51 AM
Hi Ben,

Give a try with the following code snippet to switcn the UserControl according to content in a Grid row.

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
           GridDataItem item=(GridDataItem)e.Item; 
           string strTxt=item["ProductName"].Text; 
 
            if(strTxt=="Tea"
                item.OwnerTableView.EditFormSettings.UserControlName = "WebUserControl.ascx"
            else if(strTxt=="Coffee"
                 item.OwnerTableView.EditFormSettings.UserControlName = "WebUserControl2.ascx"
        } 
         
      
    } 


Thanks
Shinu



Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or