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

In radgrid Bind DropDown to a datasource after clicking edit

6 Answers 368 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Santaji Garwe
Top achievements
Rank 1
Santaji Garwe asked on 26 Jun 2008, 05:50 AM
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>

6 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 26 Jun 2008, 07:24 AM
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.
0
Santaji Garwe
Top achievements
Rank 1
answered on 26 Jun 2008, 08:40 AM
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();
        }
    }
0
Shinu
Top achievements
Rank 2
answered on 26 Jun 2008, 09:29 AM
Hi,

Can you send your aspx?

Shinu.
0
Santaji Garwe
Top achievements
Rank 1
answered on 26 Jun 2008, 09:38 AM
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();
        }
    }

}

0
Princy
Top achievements
Rank 2
answered on 26 Jun 2008, 10:23 AM
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.
0
Justin
Top achievements
Rank 1
answered on 03 Feb 2009, 06:47 PM
Deleted post cause I was not reading closely enough

Justin
Tags
Grid
Asked by
Santaji Garwe
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Santaji Garwe
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Justin
Top achievements
Rank 1
Share this question
or