2

我有带有下拉列表的 RadGrid。我试图通过使用 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;
        }   
4

1 回答 1

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);

    }
于 2013-09-25T06:43:03.827 回答