radgrid 的问题

发布于 2024-10-07 06:45:54 字数 9466 浏览 4 评论 0原文

我在使用 RadGrid 时遇到了一些问题。一是我在 RadGrid 中有 GridClientSelectColumn。我可以使用标题复选框选择所有复选框,但无法选择单个复选框。另一个是当我单击该行时,我正在更改该行的背景颜色,但它没有完全改变。只有一半的行正在更改颜色(参见图 1)。另一个是我在 CommandItem 模板中有 RadMenu。其显示不正确(参见图 2)。这是我的代码....

<telerik:RadGrid ID="gvPjtMnt" runat="server" AutoGenerateColumns="false" Height="600px"
BorderWidth="2px" BorderStyle="Solid" BackColor="White" AllowPaging="True" PagerStyle-AlwaysVisible="true"
PageSize="20" AllowSorting="True" OnNeedDataSource="gvPjtMnt_OnNeedDataSource"
AllowFilteringByColumn="true" OnItemCommand="gvPjtMnt_ItemCommand" OnItemCreated="gvPjtMnt_ItemCreated"
OnItemDataBound="gvPjtMnt_ItemDataBound" OnPreRender="gvPjtMnt_PreRender" AllowMultiRowSelection="true"
ClientSettings-Selecting-AllowRowSelect="true">
    <HeaderStyle Height="20px" BackColor="#004000" Font-Size="8pt" Font-Bold="True" ForeColor="White"
        HorizontalAlign="Center" BorderColor="White" BorderWidth="1px" />
    <AlternatingItemStyle BackColor="#F5F5E9" HorizontalAlign="Center" BorderColor="White" />
    <ItemStyle HorizontalAlign="Center" />
    <MasterTableView GridLines="None" DataKeyNames="ProjectId" CommandItemDisplay="Top">
        <CommandItemTemplate>
            <table style="width: 100%">
                <tr align="right">
                    <td style="width: 75%">
                        <telerik:RadMenu ID="RadMenu1" runat="server" EnableRoundedCorners="true" EnableShadows="true"
                            EnableAjaxSkinRendering="true">
                            <Items>
                                <telerik:RadMenuItem Text="Text" CssClass>
                                    <Items>
                                        <telerik:RadMenuItem ImageUrl="Images/comment-icon.png" Value="1" NavigateUrl="javascript:validateChkUpdate()"
                                            Text="Add Notes">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem ImageUrl="Images/OrdUpdate.gif" Value="2" NavigateUrl="javascript:validateChkUpdate()"
                                            Text="Bulk Updates">
                                        </telerik:RadMenuItem>
                                    </Items>
                                </telerik:RadMenuItem>
                            </Items>
                        </telerik:RadMenu>
                    </td>
                    <td align="right">
                        <asp:LinkButton ID="lnkshwFilter" Text="ShowFilter" Font-Underline="true" ForeColor="MidnightBlue"
                            runat="server" OnClientClick="return showFilterItem()" />
                        <asp:LinkButton ID="lnkhdFilter" Text="HideFilter" Font-Underline="true" ForeColor="MidnightBlue"
                            runat="server" OnClientClick="return hideFilterItem()" />
                    </td>
                    <td align="right">
                        <asp:LinkButton ID="lnkclrFilter" Text="ClearFilter" Font-Underline="true" ForeColor="MidnightBlue"
                            runat="server" OnClick="lnkclrFilter_Click"></asp:LinkButton>
                    </td>
                    <td align="right">
                        Total Records found:&nbsp;<asp:Label ID="lblTotRecCount" runat="server" Font-Bold="True"
                            Font-Size="10pt" ForeColor="Black" Text="0"></asp:Label>
                    </td>
                    <td align="right" valign="middle">
                        <asp:ImageButton ID="lnkExportAll" ImageUrl="~/images/Excel.png" ToolTip="Export All"
                            runat="server" OnClick="ExportAll_Click" />
                    </td>
                    <td align="right" valign="middle">
                        <asp:ImageButton ID="ExportToExcelButton" runat="server" ImageUrl="~/images/ExportToExcel.gif"
                            ToolTip="Export to Excel" OnClick="ExportExcel_Click" />
                    </td>
                </tr>
            </table>
        </CommandItemTemplate>
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="CheckboxSelectColumn" HeaderStyle-Width="3%">
            </telerik:GridClientSelectColumn>
            <telerik:GridBoundColumn DataField="ProjectId" UniqueName="ProjectId" Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="LOB" DataField="LOB" UniqueName="LOB">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Division Name" DataField="Division" UniqueName="Division">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Region Name" DataField="MarketName" UniqueName="MarketName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Project Name" DataField="ProjectName" UniqueName="ProjectName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Project Manager Name" DataField="ProjectMgrName"
                UniqueName="ProjectMgrName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Number Of Sites Received" DataField="NumSitesReceived"
                UniqueName="NumSitesReceived">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Accept Service Order Date" DataField="AcceptServiceOrderTaskCompleteDate"
                UniqueName="AcceptServiceOrderTaskCompleteDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="PTD" DataField="PTD" UniqueName="PTD" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Health Reason" DataField="HealthReason" UniqueName="HealthReason">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Project Health" DataField="ProjectHealth" UniqueName="ProjectHealth">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Customer Signed Date" DataField="CustomerSignedDate"
                UniqueName="CustomerSignedDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="OA Complete Date" DataField="OACompleteDate"
                UniqueName="OACompleteDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Customer Requested Due Date" DataField="CustomerRequestedDueDate"
                UniqueName="CustomerRequestedDueDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Last Note Added" DataField="LastNoteAdded" HeaderStyle-Width="10%"
                UniqueName="LastNoteAdded">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn UniqueName="EditRows" HeaderStyle-Width="2%" AllowFiltering="false">
                <ItemTemplate>
                    <asp:ImageButton runat="server" ID="EditPMTsk" CommandName="EditRow" ImageUrl="Images/edit-icon.png"
                        ImageAlign="Middle" ToolTip="Edit Task" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnGridCreated="GridCreated" />
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
        <Resizing AllowColumnResize="true" EnableRealTimeResize="false" ResizeGridOnColumnResize="false"
            AllowRowResize="false" />
        <Selecting AllowRowSelect="true" />
    </ClientSettings>
</telerik:RadGrid>

cs:

protected void gvPjtMnt_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        TableCell myCell = dataItem["ProjectHealth"];
        myCell.Font.Size = 10;
        myCell.Font.Bold = true;

        if (myCell.Text.Trim() == "GREEN")
        {
            myCell.BackColor = System.Drawing.Color.Green;
            myCell.ForeColor = System.Drawing.Color.White;
        }
        if (myCell.Text.Trim() == "RED")
        {
            myCell.BackColor = System.Drawing.Color.Red;
            myCell.ForeColor = System.Drawing.Color.White;
        }
        if (myCell.Text.Trim() == "YELLOW")
        {
            myCell.BackColor = System.Drawing.Color.Yellow;
            myCell.ForeColor = System.Drawing.Color.Black;
        }
        if (myCell.Text.Trim() == "COMPLETE")
        {
            myCell.BackColor = System.Drawing.Color.Blue;
            myCell.ForeColor = System.Drawing.Color.White;
        }
    }

}

alt text

替代文本

I am getting few issues with RadGrid. One is I have GridClientSelectColumn in RadGrid. I am able to select all checkboxes using header checkbox but I am not able to select individual ones. Another is when I click the row I am changing the background color of a row but it's not coming fully. Only half of the row is changing the color (see image 1). Another one is I have RadMenu in CommandItem template. Which is not displaying properly (see image 2). Here is my code.....

<telerik:RadGrid ID="gvPjtMnt" runat="server" AutoGenerateColumns="false" Height="600px"
BorderWidth="2px" BorderStyle="Solid" BackColor="White" AllowPaging="True" PagerStyle-AlwaysVisible="true"
PageSize="20" AllowSorting="True" OnNeedDataSource="gvPjtMnt_OnNeedDataSource"
AllowFilteringByColumn="true" OnItemCommand="gvPjtMnt_ItemCommand" OnItemCreated="gvPjtMnt_ItemCreated"
OnItemDataBound="gvPjtMnt_ItemDataBound" OnPreRender="gvPjtMnt_PreRender" AllowMultiRowSelection="true"
ClientSettings-Selecting-AllowRowSelect="true">
    <HeaderStyle Height="20px" BackColor="#004000" Font-Size="8pt" Font-Bold="True" ForeColor="White"
        HorizontalAlign="Center" BorderColor="White" BorderWidth="1px" />
    <AlternatingItemStyle BackColor="#F5F5E9" HorizontalAlign="Center" BorderColor="White" />
    <ItemStyle HorizontalAlign="Center" />
    <MasterTableView GridLines="None" DataKeyNames="ProjectId" CommandItemDisplay="Top">
        <CommandItemTemplate>
            <table style="width: 100%">
                <tr align="right">
                    <td style="width: 75%">
                        <telerik:RadMenu ID="RadMenu1" runat="server" EnableRoundedCorners="true" EnableShadows="true"
                            EnableAjaxSkinRendering="true">
                            <Items>
                                <telerik:RadMenuItem Text="Text" CssClass>
                                    <Items>
                                        <telerik:RadMenuItem ImageUrl="Images/comment-icon.png" Value="1" NavigateUrl="javascript:validateChkUpdate()"
                                            Text="Add Notes">
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem ImageUrl="Images/OrdUpdate.gif" Value="2" NavigateUrl="javascript:validateChkUpdate()"
                                            Text="Bulk Updates">
                                        </telerik:RadMenuItem>
                                    </Items>
                                </telerik:RadMenuItem>
                            </Items>
                        </telerik:RadMenu>
                    </td>
                    <td align="right">
                        <asp:LinkButton ID="lnkshwFilter" Text="ShowFilter" Font-Underline="true" ForeColor="MidnightBlue"
                            runat="server" OnClientClick="return showFilterItem()" />
                        <asp:LinkButton ID="lnkhdFilter" Text="HideFilter" Font-Underline="true" ForeColor="MidnightBlue"
                            runat="server" OnClientClick="return hideFilterItem()" />
                    </td>
                    <td align="right">
                        <asp:LinkButton ID="lnkclrFilter" Text="ClearFilter" Font-Underline="true" ForeColor="MidnightBlue"
                            runat="server" OnClick="lnkclrFilter_Click"></asp:LinkButton>
                    </td>
                    <td align="right">
                        Total Records found: <asp:Label ID="lblTotRecCount" runat="server" Font-Bold="True"
                            Font-Size="10pt" ForeColor="Black" Text="0"></asp:Label>
                    </td>
                    <td align="right" valign="middle">
                        <asp:ImageButton ID="lnkExportAll" ImageUrl="~/images/Excel.png" ToolTip="Export All"
                            runat="server" OnClick="ExportAll_Click" />
                    </td>
                    <td align="right" valign="middle">
                        <asp:ImageButton ID="ExportToExcelButton" runat="server" ImageUrl="~/images/ExportToExcel.gif"
                            ToolTip="Export to Excel" OnClick="ExportExcel_Click" />
                    </td>
                </tr>
            </table>
        </CommandItemTemplate>
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="CheckboxSelectColumn" HeaderStyle-Width="3%">
            </telerik:GridClientSelectColumn>
            <telerik:GridBoundColumn DataField="ProjectId" UniqueName="ProjectId" Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="LOB" DataField="LOB" UniqueName="LOB">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Division Name" DataField="Division" UniqueName="Division">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Region Name" DataField="MarketName" UniqueName="MarketName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Project Name" DataField="ProjectName" UniqueName="ProjectName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Project Manager Name" DataField="ProjectMgrName"
                UniqueName="ProjectMgrName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Number Of Sites Received" DataField="NumSitesReceived"
                UniqueName="NumSitesReceived">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Accept Service Order Date" DataField="AcceptServiceOrderTaskCompleteDate"
                UniqueName="AcceptServiceOrderTaskCompleteDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="PTD" DataField="PTD" UniqueName="PTD" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Health Reason" DataField="HealthReason" UniqueName="HealthReason">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Project Health" DataField="ProjectHealth" UniqueName="ProjectHealth">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Customer Signed Date" DataField="CustomerSignedDate"
                UniqueName="CustomerSignedDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="OA Complete Date" DataField="OACompleteDate"
                UniqueName="OACompleteDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Customer Requested Due Date" DataField="CustomerRequestedDueDate"
                UniqueName="CustomerRequestedDueDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderText="Last Note Added" DataField="LastNoteAdded" HeaderStyle-Width="10%"
                UniqueName="LastNoteAdded">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn UniqueName="EditRows" HeaderStyle-Width="2%" AllowFiltering="false">
                <ItemTemplate>
                    <asp:ImageButton runat="server" ID="EditPMTsk" CommandName="EditRow" ImageUrl="Images/edit-icon.png"
                        ImageAlign="Middle" ToolTip="Edit Task" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnGridCreated="GridCreated" />
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
        <Resizing AllowColumnResize="true" EnableRealTimeResize="false" ResizeGridOnColumnResize="false"
            AllowRowResize="false" />
        <Selecting AllowRowSelect="true" />
    </ClientSettings>
</telerik:RadGrid>

.cs:

protected void gvPjtMnt_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        TableCell myCell = dataItem["ProjectHealth"];
        myCell.Font.Size = 10;
        myCell.Font.Bold = true;

        if (myCell.Text.Trim() == "GREEN")
        {
            myCell.BackColor = System.Drawing.Color.Green;
            myCell.ForeColor = System.Drawing.Color.White;
        }
        if (myCell.Text.Trim() == "RED")
        {
            myCell.BackColor = System.Drawing.Color.Red;
            myCell.ForeColor = System.Drawing.Color.White;
        }
        if (myCell.Text.Trim() == "YELLOW")
        {
            myCell.BackColor = System.Drawing.Color.Yellow;
            myCell.ForeColor = System.Drawing.Color.Black;
        }
        if (myCell.Text.Trim() == "COMPLETE")
        {
            myCell.BackColor = System.Drawing.Color.Blue;
            myCell.ForeColor = System.Drawing.Color.White;
        }
    }

}

alt text

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

儭儭莪哋寶赑 2024-10-14 06:45:54

将尝试尽可能简短:

  1. 如何有条件地设置 Telerik 网格行的样式 - doc< /a>
  2. 复选框选择列应该适用于全选和单选 - 检查网站上的 javascript 错误是否阻止
  3. 我看到根菜单项的 CssClass 属性为空 - 这会破坏其渲染吗?另请检查您为内部项目设置的图像 URL 是否有效。

Will try to be as brief as possible:

  1. How to style telerik grid rows conditionally - doc
  2. The checkbox-select column should work both for select all and select single - check if javascript errors on the site prevent that
  3. I see that you have empty CssClass attribute for the root menu item - can this spoil its rendering? Also check if the image urls you set for the inner items are valid.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文