使用Eval在ItemTemplate中设置AutoPostBack属性

时间:2013-05-17 16:08:01

标签: c# asp.net eval telerik-grid itemtemplate

我正在使用来自Telerik的RadGrid,并尝试根据页面上其他地方的RadioButtonList切换AutoPostBack的{​​{1}}媒体资源。

CheckBox

我收到错误:<telerik:RadGrid ID="rg" runat="server" Skin="Office2010Silver" GridLines="Both" OnNeedDataSource="rg_NeedDataSource" OnItemDataBound="rg_ItemDataBound"> <MasterTableView Width="100%" DataKeyNames="StudentID, Response, Tested"> <Columns> <telerik:GridBoundColumn UniqueName="StudentName" HeaderText="Student Name" DataField="StudentName"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="StudentID" HeaderText="Student ID" DataField="StudentID"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Answer" HeaderText="Answer" DataField="Answer"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Response" HeaderText="Score" DataField="Response"></telerik:GridBoundColumn> <telerik:GridTemplateColumn HeaderText="Score" ItemStyle-Wrap="false"> <ItemTemplate> <asp:RadioButtonList ID="rblScore" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal" OnSelectedIndexChanged="rblScore_IndexChanged" AutoPostBack='<%#Eval(chkAutoSave.Checked.ToString()) %>'></asp:RadioButtonList> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid> 不包含名称为DataBinding: 'System.Data.DataRowView'的属性。是否可以这样做,或者我是否需要在True内完成此操作?

2 个答案:

答案 0 :(得分:0)

我继续使用ItemDataBound并且工作正常......但是如果有人有解决方案,我会感兴趣。

答案 1 :(得分:0)

首先向模板列提供ID

 <telerik:GridTemplateColumn HeaderText="Score" ItemStyle-Wrap="false" ID="Score">
                <ItemTemplate>
                    <asp:RadioButtonList ID="rblScore" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal" OnSelectedIndexChanged="rblScore_IndexChanged" AutoPostBack='<%#Eval(chkAutoSave.Checked.ToString()) %>'></asp:RadioButtonList>
                </ItemTemplate>
            </telerik:GridTemplateColumn>

代码背后:

  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
    if (e.Item is GridDataItem)
                            {
    GridDataItem dataBoundItem = e.Item as GridDataItem;
    Bool _boolChecked=Convert.ToBoolean(dataBoundItem["chkAutoSave.Checked"].toString());
              ((RadioButtonList )dataBoundItem["Score"].FindControl("rblScore")).AutoPostBack= _boolChecked;
    }
    }

此致