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

populate Dropdownlist in Formtemplate

1 Answer 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dingen
Top achievements
Rank 1
dingen asked on 05 Feb 2010, 11:56 AM
hi

I am trying to populate a dropdownlist(ddl2) based on a the selectedvalue of  ddl1 ?

D

Imports Telerik.Web.UI 
 
Partial Class dropdowninformtemplate 
    Inherits System.Web.UI.Page 
 
 
    Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated 
        If e.Item.ItemType = Telerik.Web.UI.GridItemType.EditFormItem And e.Item.IsInEditMode Then 
 
            Dim item As GridEditFormItem 
            item = e.Item 
 
            Dim ddl As DropDownList = CType(item.FindControl("ddl1"), DropDownList) 
            Dim cmb As RadComboBox = item.FindControl("cmb"
 
            AddHandler ddl.SelectedIndexChanged, AddressOf ddl1_SelectedIndexChanged 
       
            ddl.DataSource = DataConnection.GetDataTable("select * from products"
            ddl.DataTextField = "productname" 
            ddl.DataValueField = "productid" 
            ddl.DataBind() 
        End If 
    End Sub 
 
 
    Protected Sub ddl1_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs) 
        'populate ddl2 
 
 
    End Sub 
 
    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand 
 
        If e.Item.IsInEditMode Then 
            Dim item As GridEditFormItem 
            item = CType(e.Item, GridEditFormItem) 
 
            Dim ddl2 As DropDownList = item.FindControl("ddl2"
 
 
        End If 
 
 
    End Sub 
 
    Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource 
        RadGrid1.DataSource = DataConnection.GetDataTable("select * from customers"
 
    End Sub 
 
   
End Class 
 


put the DataConnection class in the App_Code folder:

Imports Microsoft.VisualBasic 
Imports System.Data 
Imports System.Data.SqlClient 
 
 
Public Class DataConnection 
 
 
    Public Shared Function GetDataTable(ByVal query As StringAs DataTable 
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString 
        Dim conn As SqlConnection = New SqlConnection(ConnString) 
        Dim adapter As SqlDataAdapter = New SqlDataAdapter 
        adapter.SelectCommand = New SqlCommand(query, conn) 
        Dim table1 As New DataTable 
        conn.Open() 
        Try 
            adapter.Fill(table1) 
        Finally 
            conn.Close() 
        End Try 
        Return table1 
    End Function 
End Class 
 

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="dropdowninformtemplate.aspx.vb" 
    Inherits="dropdowninformtemplate" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
    <div> 
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
        <telerik:RadGrid ID="RadGrid1" runat="server"
            <MasterTableView EditMode="EditForms"
                <Columns> 
                    <telerik:GridEditCommandColumn> 
                    </telerik:GridEditCommandColumn> 
                </Columns> 
                <EditFormSettings EditFormType="Template"
                    <FormTemplate> 
                        <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true"
                        </asp:DropDownList> 
                        <asp:DropDownList ID="ddl2" runat="server"
                        </asp:DropDownList> 
                    </FormTemplate> 
                </EditFormSettings> 
            </MasterTableView> 
        </telerik:RadGrid> 
    </div> 
    </form> 
</body> 
</html> 
 

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 08 Feb 2010, 08:04 AM
Hello Dingen,

You can check the approach demonstrated in this help topic:

Referencing controls in grid row/edit form

Regards,
Martin
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Grid
Asked by
dingen
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or