radgrid的问题

时间:2010-12-13 19:38:24

标签: c# telerik radgrid

我对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

alt text

1 个答案:

答案 0 :(得分:0)

尽量做到尽可能简短:

  1. 如何有条件地设置telerik网格行的样式 - doc
  2. 复选框选择列应该同时用于全选并选择单一 - 检查网站上的javascript错误是否会阻止
  3. 我看到根菜单项有空CssClass属性 - 这会破坏它的渲染吗?还要检查为内部项目设置的图像URL是否有效。