In radgrid Bind DropDown to a datasource after clicking edit

7 posts, 1 answers
  1. Santaji Garwe
    Santaji Garwe avatar
    10 posts
    Member since:
    Mar 2008

    Posted 26 Jun 2008 Link to this post

    hi,
    I  am using a rad grid and for editing the data i am using editform editing of template type.
    I actually want to bind the dropdown in template form to a datasource after edit is clicked in edit column of datagrid



    <Columns>
                        <telerik:GridBoundColumn SortExpression="ShortName" HeaderText="ShortName" DataField="ShortName" HeaderButtonType="TextButton" UniqueName="ShortName"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn  SortExpression="CategoryId" HeaderText="Id" DataField="CategoryId" HeaderButtonType="TextButton" Visible="False" Display="False" UniqueName="CategoryId"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn SortExpression="Description" HeaderText="Description" DataField="Description" HeaderButtonType="TextButton" UniqueName="Description"></telerik:GridBoundColumn>
                        <telerik:GridEditCommandColumn UniqueName="EditCol">
                        </telerik:GridEditCommandColumn>
                    </Columns>
                   
                    <EditFormSettings EditFormType="Template">
                        <EditColumn UniqueName="EditCol">
                       
                        </EditColumn>
                        <FormTemplate>
                            <table id="Table1">
                            <tr>
                                <td>
                                    Short Name
                                </td>
                                <td>
                                    <asp:DropDownList ID="DD1" runat="server"> </asp:DropDownList>
                                </td>
                           
                            </tr>
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Jun 2008 Link to this post

    Hi,

    Try the following code snippet in the ItemDataBound event.

    CS:
    protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
            { 
                GridEditFormItem editform = (GridEditFormItem)e.Item; 
                DropDownList ddl = (DropDownList)editform.FindControl("DD1"); 
                ddl.DataSourceID = "SqlDataSource1"
            } 
        } 


    Thanks
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Santaji Garwe
    Santaji Garwe avatar
    10 posts
    Member since:
    Mar 2008

    Posted 26 Jun 2008 Link to this post

    it was not able to find control .dd1 was null

    protected void RadGrid1_EditCommand(object source, GridItemEventArgs e)
        {
            if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
            {
                GridEditFormItem gitem = (GridEditFormItem)e.Item;
                DropDownList dd1 = (DropDownList)gitem.FindControl("DD1");
                dd1.DataSource=AvailableRecordStatusList.GetStatusList();
            }
        }
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Jun 2008 Link to this post

    Hi,

    Can you send your aspx?

    Shinu.
  6. Santaji Garwe
    Santaji Garwe avatar
    10 posts
    Member since:
    Mar 2008

    Posted 26 Jun 2008 Link to this post

    code for aspx file

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="RadCont.ascx.cs" Inherits="RadCont" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <table id="Tab">

        <tr>
            <td>
            <asp:SqlDataSource
                ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CAAConnectionString %>"
                SelectCommand="SELECT [name] FROM [record_status]">
            </asp:SqlDataSource>
           
           
                <telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="False" runat="server" GridLines="None" OnItemEvent="RadGrid2_ItemDataBound" >
               
                <MasterTableView  DataKeyNames="CategoryId">
                <DetailTables>
                    <telerik:GridTableView DataKeyNames="ParameterVal" Name="Value">
                       
                   
                    </telerik:GridTableView>
                </DetailTables>
                    <Columns>
                        <telerik:GridBoundColumn SortExpression="ShortName" HeaderText="ShortName" DataField="ShortName" HeaderButtonType="TextButton" UniqueName="ShortName"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn  SortExpression="CategoryId" HeaderText="Id" DataField="CategoryId" HeaderButtonType="TextButton" Visible="False" Display="False" UniqueName="CategoryId"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn SortExpression="Description" HeaderText="Description" DataField="Description" HeaderButtonType="TextButton" UniqueName="Description"></telerik:GridBoundColumn>
                        <telerik:GridEditCommandColumn UniqueName="EditCol">
                        </telerik:GridEditCommandColumn>
                    </Columns>
                   
                    <EditFormSettings EditFormType="Template">
                        <EditColumn UniqueName="EditCol">
                       
                        </EditColumn>
                        <FormTemplate>
                            <table id="Table1">
                            <tr>
                                <td>
                                    Short Name
                                </td>
                                <td>
                                    <asp:DropDownList ID="DD1"  runat="server"> </asp:DropDownList>
                                   
                                </td>
                           
                            </tr>
                           
                           
                            </table>
                       
                       
                        </FormTemplate>
                        <PopUpSettings ScrollBars="None" />
                    </EditFormSettings>
                    <ExpandCollapseColumn Resizable="False" Visible="False">
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
                    <RowIndicatorColumn Visible="False">
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                </MasterTableView>
                <ClientSettings AllowColumnsReorder="True">
                   
                </ClientSettings>
                </telerik:RadGrid>
            </td>
       

        </tr>



    </table>


    code behind

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using JMS.CAA.BusinessLibrary;
    using Telerik.Web.UI;

    public partial class RadCont : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadGrid1_NeedDataSource(sender, new GridNeedDataSourceEventArgs(GridRebindReason.InitialLoad));
        }

        protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            ParameterCategoryList pclist = ParameterCategoryList.NewParameterCategoryList();
            pclist = ParameterCategoryList.GetParameterCategoryList(new Guid("4EF52DD9-6875-4ACE-A176-3AAACE78A502"));
            RadGrid1.DataSource = pclist;

            ParameterValueList pvlist = ParameterValueList.NewParameterValueList();
           
        }


        protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
            {
                GridEditFormItem editform = (GridEditFormItem)e.Item;
                DropDownList ddl = (DropDownList)editform.FindControl("DD1");
                ddl.DataSource = AvailableRecordStatusList.GetStatusList();
            }
        }

    }

  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Jun 2008 Link to this post

    Hi Santaji,

    Have you set the proper ItemDataBound event handler? Try setting it as shown below.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server"   AllowPaging="True" DataSourceID="SqlDataSource3"   OnItemDataBound="RadGrid2_ItemDataBound"  > 


    CS:
     protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))  
            {  
                GridEditFormItem editform = (GridEditFormItem)e.Item;  
                DropDownList ddl = (DropDownList)editform.FindControl("DD1");  
                 
            }  
       } 


    Thanks
    Princy.
  8. Justin
    Justin avatar
    35 posts
    Member since:
    Apr 2008

    Posted 03 Feb 2009 Link to this post

    Deleted post cause I was not reading closely enough

    Justin
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017