Telerik RadGrid需要编辑模式

时间:2014-07-07 12:11:26

标签: telerik radgrid

我的.aspx文件中有以下内容。当用户点击“编辑”时,我喜欢它以显示可以更新或取消的表单。目前,当我点击“编辑”时,它什么也没做。请注意,我正在从后面的代码处理数据源。因此,我在RadGrid的.aspx文件中没有DataSource:

这是我的代码:

     <telerik:RadGrid ID="rdClosedLoop" runat="server" GridLines="None" OnDeleteCommand="DeleteClosedLoop"
                Skin="Metro" ActiveItemStyle-HorizontalAlign="Center"  AutoGenerateEditColumn="true" >
                <MasterTableView EditMode="EditForms" AutoGenerateColumns="False" DataKeyNames="ID" >                       
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
                    <Columns>                                                         


                          <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID"  EditFormColumnIndex="0"
                            UniqueName="ID" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn>    

                        <telerik:GridBoundColumn DataField="ActiveInhibitor" HeaderText="ActiveInhibitor" SortExpression="ActiveInhibitor"  EditFormColumnIndex="0"
                            UniqueName="ActiveInhibitor" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn>      



                        <telerik:GridBoundColumn DataField="Conductivity" HeaderText="Conductivity" SortExpression="Conductivity"  EditFormColumnIndex="0"
                            UniqueName="Conductivity" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn>                                                                                               

                         <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                        </telerik:GridButtonColumn>

                    </Columns>

                      <EditFormSettings ColumnNumber="1" CaptionFormatString="Edit for ID {0}"
                CaptionDataField="ID">
                <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%">
                </FormMainTableStyle>
                <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module"
                    Height="110px" Width="100%"></FormTableStyle>
                <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
                <EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                </EditColumn>
                <FormTableButtonRowStyle HorizontalAlign="Left" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
            </EditFormSettings>

                </MasterTableView>
                <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" EnableImageSprites="True">
                </HeaderContextMenu>
            </telerik:RadGrid>

代码背后:

    protected void btnClosedLoop_Click(object sender, EventArgs e)
    {
        // Note - verId is based on some conditions

        var resultCLList = (from ms in db.ver_ClosedLoop
                        where ms.VerificationId == verId
                        select ms).ToList();


        rdClosedLoop.DataSource = resultCLList;
        rdClosedLoop.DataBind();

    }

1 个答案:

答案 0 :(得分:0)

请尝试使用以下代码段。

<强> ASPX

<telerik:RadGrid ID="rdClosedLoop" runat="server" GridLines="None" 
        Skin="Metro" ActiveItemStyle-HorizontalAlign="Center" AutoGenerateEditColumn="true"
        OnItemCommand="rdClosedLoop_ItemCommand">
        <MasterTableView EditMode="EditForms" AutoGenerateColumns="False" DataKeyNames="ID">
            <RowIndicatorColumn>
                <HeaderStyle Width="20px" />
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px" />
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" EditFormColumnIndex="0"
                    UniqueName="ID" HeaderStyle-HorizontalAlign="Center">
                </telerik:GridBoundColumn>
                <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                </telerik:GridButtonColumn>
            </Columns>
            <EditFormSettings ColumnNumber="1" CaptionFormatString="Edit for ID {0}" CaptionDataField="ID">
                <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%">
                </FormMainTableStyle>
                <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module"
                    Height="110px" Width="100%"></FormTableStyle>
                <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
                <EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                </EditColumn>
                <FormTableButtonRowStyle HorizontalAlign="Left" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
            </EditFormSettings>
        </MasterTableView>
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" EnableImageSprites="True">
        </HeaderContextMenu>
    </telerik:RadGrid>

<强> ASPX.CS

protected void Button1_Click(object sender, EventArgs e)
{
    rdClosedLoop.DataSource = getDummyData(0);
    rdClosedLoop.DataBind();
}

protected DataTable getDummyData(int verId)
{
    // Note - verId is based on some conditions

    DataTable dt = new DataTable();
    dt.Columns.Add("ID",typeof(int));
    dt.Rows.Add(1);
    dt.Rows.Add(2);
    dt.Rows.Add(3);

    return dt;
}

protected void rdClosedLoop_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.EditCommandName)
    {
        rdClosedLoop.DataSource = getDummyData(0);
        rdClosedLoop.DataBind();
    }
}

如果有任何疑虑,请告诉我。