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

[Solved] Accessing Dropdown list on "Edit" ItemCommand

2 Answers 190 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 2
Richard asked on 03 Apr 2009, 11:35 AM
Hello

How do I access a Dropdown List in "Edit" ItemCommand mode?  I need to do something with the control but I am having problems finding it.

                            <telerik:GridTemplateColumn HeaderText="Group" UniqueName="tcGroup" Visible="False">  
                                <EditItemTemplate> 
                                    <asp:DropDownList ID="ddlGroupID" runat="server" DataSourceID="sdsVL_Groups" DataTextField="Name" 
                                        DataValueField="GroupID" SelectedValue='<%# Bind("GroupID_FK") %>' AppendDataBoundItems="True">  
                                        <asp:ListItem></asp:ListItem> 
                                    </asp:DropDownList> 
                                </EditItemTemplate> 
                            </telerik:GridTemplateColumn> 

Private Sub rgResource_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgResource.ItemCommand  
 
Select Case e.CommandName  
  Case "Edit" 
     ' REMOVE THE BLANK LISTITEM FROM THE DROPDOWLIST  
End Select 

I am trying to remove the blank listitem from dropdown once it goes into Edit mode.  The blank element is there for the "Add New Record" "bug when bound to a datasource".

Thanks

2 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 2
answered on 03 Apr 2009, 12:28 PM

I found an alternative way to achieve this which is to do it during ItemCreated:

Distinguish edit/insert mode on ItemCreated/ItemDataBound:
http://www.telerik.com/help/aspnet-ajax/grddistinguisheditinsertmodeonitemcreateditemdatabound.html

 


But still, if there is a way of accessing controls in Edit mode I would be very much interested.

Cheers
R
0
Princy
Top achievements
Rank 2
answered on 03 Apr 2009, 12:29 PM
Hello Richard,

Try accessing the dropdownlist in ItemDataBound event instead of ItemComand.

VB:
Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs)  
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then 
        Dim dataItem As GridDataItem = TryCast(e.Item, GridDataItem)  
        Dim dropdown As DropDownList = DirectCast(dataItem("tcGroup").FindControl("ddlGroupID"), DropDownList)  
    End If 
End Sub 

Thanks,
Princy.
Tags
Grid
Asked by
Richard
Top achievements
Rank 2
Answers by
Richard
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or