检索RadGrid控件下拉列表选定的值

时间:2013-09-24 20:10:24

标签: asp.net telerik telerik-grid

我有RadGrid和DropDownlist。我试图通过循环使用javascript找到每个控件的值,我得到findcontrol为' null'。我已将OnClientRatingSelectedIndexChanged附加到下拉列表的代码中。  可能有什么不对?我很感激任何建议。

  <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AlternatingItemStyle-HorizontalAlign="Left"
                               OnNeedDataSource="RadGrid1_NeedDataSource">
                                <MasterTableView DataKeyNames="level_id" PageSize="10">
                                    <Columns>
 <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Test"
                                            Visible="true">
                                            <ItemTemplate>
                                                <asp:Panel ID="Panel1" runat="server">
                                                    <asp:DropDownList ID="Drop1" runat="server"                                                                                                                                        AutoPostBack="true">
                                                    </asp:DropDownList>
                                                </asp:Panel>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                  </Columns>
</MasterTableView>
</telerik:RadGrid>

的Javascript

   function OnClientRatingSelectedIndexChanged(arg) {

        var grid = $find("<%=RadGrid1.ClientID %>");
        var MasterTable = grid.get_masterTableView();
        var Rows = MasterTable.get_dataItems();
        for (var i = 0; i < Rows.length; i++) {
            var row = Rows[i];
            var drop1 = row.findControl("Drop1");  
            var val1 = drop1.selectedValue;
        }   

1 个答案:

答案 0 :(得分:1)

试试这个:

protected void Radgrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            DropDownList list = (DropDownList)item.FindControl("DropDownList1");
            list.Attributes.Add("onChange", "OnSelectedIndexChange('" + item.ItemIndex + "');");
        }
    }

JS:

function OnSelectedIndexChange(rowindex) {
        var grid = $find("<%=Radgrid1.ClientID %>");
        var MasterTable = grid.get_masterTableView();
        var drop1 = MasterTable.get_dataItems()[rowindex].findElement('DropDownList1');
        alert(drop1.value);

    }