how to fill dropdown in telerik grid databound?

亡梦爱人 提交于 2019-12-13 04:59:41

问题


i have a telerik grid and use GridTemplateColumn as bellow

<telerik:GridTemplateColumn DataField="Status" ReadOnly="true" UniqueName="colStatus" HeaderText="Status">  
    <ItemTemplate>
        <asp:Label ID="lblStatus" runat="server"></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:DropDownList ID="drpstatus" runat="server" />
    </EditItemTemplate>                                    
</telerik:GridTemplateColumn> 

then i fill dropdown and label in ItemDataBound event :

protected void grdList_ItemDataBound(object sender, GridItemEventArgs e)
{

            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                {
                    GridEditableItem editItem = (GridEditableItem)e.Item;
                    var info = (ProductViewInfo)e.Item.DataItem;
                    DropDownList drpstatus = (DropDownList)editItem["colStatus"].FindControl("drpstatus");
                    var cntType = new ProductTypeController();
                    var lst = cntType.GetStatusList(PortalId, enumTypes.MainGroup);
                    drpstatus.DataSource = lst;
                    drpstatus.DataTextField = "Caption";
                    drpstatus.DataValueField = "StatusID";
                    drpstatus.DataBind();
                    drpstatus.SelectedValue = info.Status.ToString();
                }
                else
                {
                    var item = e.Item as GridDataItem;
                    var info = (ProductViewInfo)item.DataItem;

                    Label lblStatus = (Label)item["colStatus"].FindControl("lblStatus"); 
                    lblStatus.Text = info.StatusCaption;
                }
            }
 }

but my drop down does not fill! "e.Item.IsInEditMode" always returns false. should i add anything else in order to fill dropdown?


回答1:


I guess the problem related to ReadOnly="true" try to remove it



来源:https://stackoverflow.com/questions/24132839/how-to-fill-dropdown-in-telerik-grid-databound

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!