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

insert/update usecontrol gridtemplatecolumn

1 Answer 44 Views
This is a migrated thread and some comments may be shown as answers.
first last
Top achievements
Rank 1
first last asked on 08 Dec 2008, 11:23 PM

I have a
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register src="WebUserControl.ascx" tagname="WebUserControl" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"  
            AllowSorting="True" GridLines="None"  
            onneeddatasource="RadGrid1_NeedDataSource" AllowAutomaticDeletes="True"  
            AllowAutomaticInserts="True" AllowAutomaticUpdates="True"  
            AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
<HeaderStyle Width="20px"></HeaderStyle>
<HeaderStyle Width="20px"></HeaderStyle>
<telerik:GridTemplateColumn HeaderText="someheader">
some user control
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
<FilterMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

And the usercontrol:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:ListBox ID="ListBox1"  SelectionMode="Multiple" runat="server">

how do i get the values from the listbox in the usercontrol when performing a save or update? and how do i select pre-defined values(the ones saved in an edit to a db) in the listbox when displaying it in itemtemplate?


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 11 Dec 2008, 02:16 PM
Hi Kjartan,

You can reference the listbox from the user control inside the edit template by its id inside the UpdateCommand/InsertCommand handler of the grid as follows:

ListBox lbox = e.Item.FindControl("WebUserControl1").FindControl("ListBox1") as ListBox;

To set the selected value in the listbox to match the underlying source field value, intercept the ItemDataBound event of the grid and use the following code implementation:

private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
if(e.Item is GridEditFormItem && e.Item.IsInEditMode)  
  ListBox lbox = e.Item.FindControl("WebUserControl1").FindControl("ListBox1"as ListBox;  
   string selValue = DataBinder.Eval(e.Item.DataItem, "<MySourceFieldName>").ToString();  
  //select the item in the listbox which matches the selValue value  

Best regards,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
first last
Top achievements
Rank 1
Answers by
Telerik team
Share this question