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

RadGrid User Control

3 Answers 209 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 02 May 2014, 05:55 PM
Does anyone have a good example of how to add a user control in a gridtemplate column in a radgrid.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 May 2014, 06:23 AM
Hi Michael,

Your requirement is not enough to help you with your scenario. can you please elaborate on it. Meanwhile you can take a look at this demo, which has a template column which opens a window for edit which contains the UserControl form.
Window Editing

Thanks,
Shinu
0
Michael
Top achievements
Rank 1
answered on 05 May 2014, 11:30 AM
I would like to add a user control  within a gridtemplate column and not call a popup form.  Here's a link to a similar question:

http://www.telerik.com/forums/add-user-control-to-gridview-column

0
Shinu
Top achievements
Rank 2
answered on 06 May 2014, 05:58 AM
Hi Michael,

Please take a look at the below sample code snippet. If this doesn't help, elaborate your requirement and provide code if necessary.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
    AllowPaging="true" AllowSorting="true" OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn>
                <ItemTemplate>
                    <uc1:WebUserControl ID="WebUserControl1" runat="server" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

ASPX.CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
   GridDataItem dataItem = (GridDataItem)e.Item;
   RadComboBox radcomboCountry = dataItem.FindControl("WebUserControl1").FindControl("RadComboBoxCountry") as RadComboBox;
   radcomboCountry.SelectedValue = DataBinder.Eval(dataItem.DataItem, "ShipCountry").ToString();
  }
}

ASCX:
<telerik:RadComboBox ID="RadComboBoxCountry" runat="server" DataSourceID="SqlDataSource1" DataTextField="ShipCountry" DataValueField="ShipCountry">
</telerik:RadComboBox>
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT  distinct [ShipCountry] FROM [Orders]"></asp:SqlDataSource>

Thanks,
Shinu
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Share this question
or